In the third and final part of this blog series, I’ll focus on building a parser to grab our data from Intellect and send it on up to AT&T’s M2X platform.
So now that our Arduino is pulling some measurements and sending them to a properly configured RPMA DevKit board (rACM), it’s time to pull that data out of Intellect and send it on to M2X. This part got pretty tricky for me, as it was my first real foray into Python. Plus, M2X is really picky about the data you feed it.
Our Starter Pack includes a handful of REST examples that you can use to read device data, send data downstream to a device from the cloud, and so on. The readmeConsole.txt doc is surprisingly helpful here. Read it! Our engineers have crafted a few parsers that work with M2X, but the serial example is limited to a single value. Since we’re sending two values in one string, we’ll have to split it up with a custom parser before sending it up to M2X. There are three files that we’re going to modify in our M2M_REST_Examples folder: createDevices.py, parsers.py, and restm2x.py.
First, let’s update createDevices.py with our device info and some API keys from M2X. You created an account on M2X, right? Open createDevices.py with the editor of your choice (I just use TextEdit.app on my Mac). You’ll likely be greeted by a bewildering array of various devices. Time to add ours to the mix! Delete all but one, which we’ll modify to meet our needs.
Make yours like mine. Your nodeId can be found by running that GET_DEVICE_STATUS command from Part 2, or peering at the top of your development board. It’s the many-digits-long value under MAC on the module sticker.
After creating an M2X account, you’re offered the chance to create a device. Make yours numerical! If it prompts you to create your first stream, name it temp_f and then name a second stream humidity. Then copy-paste Device ID and Primary API keys from M2X into createDevices.py. Save your changes and you’re done there. Take care throughout this whole process that your text editor doesn’t change apostrophes and quotation marks from straight-up-and-down marks to fancy curved open and close marks. TextEdit.app does this by default and it is absolutely maddening.
Next up we’ll need to add our new parser to parsers.py. I ended up modifying the existing Serial Uplink parser to handle an additional sensor, and it did the trick. The changes I made should be pretty self-explanatory. I’m not going to get into the different sensorIds and sensorTypes: they’re explained over in readmeConsole.txt. Go ahead and add the following code somewhere amongst the existing parsers and save the document.
Modifying rest2m2x.py was kind of a beast for me, but I’m going to put most of the blame on M2X for being such a stickler about the data it can process. I began the whole thing by modifying the existing serial example provided in the script. I’m absolutely sure that someone with more experience could have handled parsing the Arduino’s string into two separate numerical values more efficiently than I. Bear with me, please.
While this script is running, it pulls data from Intellect and parses data from our device, and then sends the data up to M2X. Since the Arduino is transmitting a text string with an underscore ‘_’ between the two values, we need to split the string up and send each value separately to M2X. Since M2X is particular about the sort of stuff we send over, I also have each string segment run through a filter that removes any hidden non-numerical characters, leaving the pure data behind. Then we send each value to separate M2X streams; in this case humidity and temp_f.
We’re almost there! You have to update ATT_Devices.json by running the following command: ‘python createDevices.py’ which will populate ATT_Devices.json with your RPMA DevKit’s info. Now, if everything has been inputted correctly, you should be able to run rest2m2x.py and have your data kicked up into M2X. Log in to M2X and watch the data pour in!
That’s it! You’re done! What are you still doing here? Well, yes, I did learn a bunch of things from this exercise. Developing a sensor solution with RPMA connectivity in mind turns out to be super easy. Pair an Arduino or Raspberry Pi to one of our RPMA DevKits and you get a surprisingly potent proof of concept for your IoT application that doesn’t take a lot of technical know-how to get going. Request an RPMA DevKit below and start cracking!
Share This :