Home › Forums › Mayfly Data Logger › Using Xbee Cellular Modem with ThingSpeak › Reply To: Using Xbee Cellular Modem with ThingSpeak
Here are the python files if you ever decide to look at that option. Please feel free to manipulate however you need to.
- Open up the main.py file in a ‘python’ editor and use the credentials you get from the MQTT device you created on thingspeak, not your API keys. Save file.
- Within Digi XTCU you will need to go to File System Manager on the Xbee and go into the “lib” folder.
- Create a folder named umqtt. (right click, create directory, name it, enter) Place the simple.py file in that folder.
- Go back to the main /flash directory (should show cert and lib folders) and transfer the main.py file into that location.
This main file does a few different things. Sorry, I didn’t want to completely rewrite the file so I used a lot of what I already had in place and deleted the FTPS portions.
- It will recognize data that it needs to publish from the mayfly be adding 2 things.
- #P on the front of the data string (no space between this and the actual data)
- ‘\n’ on the end of the data string (println() from mayfly for each data string you want to send works)
- so….. #Pfield1=xx&field2=xx&field3=xx……\r\n
- python uses the \n to separate the strings and then trims the \r later.
- you can send multiple strings at once as long as each one has these two identifiers on the front and back and this file will split them into individual posts.
- Because there may be times where you loose the cell tower, this file creates a couple of files to log the data in case it can’t post. There is a topic file and a message file. Each time a post comes in for publishing it will first back it up to the files. Once it posts then it will clear the file. Does the same thing for power outages. If you have backed up messages that still need to post and you lose power, it will read those logs on boot and place them in a buffer to send. Once they all send it will clear the files.
within the main.py there are some print statements I had in there while troubleshooting this connection. You can comment them out if needed. I also connected my XCTU profile if you want to dump this to the XBee for settings establishment (profile -> apply profile). I’m on 11417 firmware so you may want to update to that if you want to use it. The only thing you should need to change would be your apn. I use twilio super sims and the apn is different.
Please let me know if you have any questions. I know this is a fair bit of info. more good info on the python aspect of XBee is here: