I am using a Particle.io Electron as a gateway for many end nodes. I was wondering if anyone had a best practice or preferred method to get the data to Ubidots using the least amount of data possible.
It has to be a cellular deployment, so my goal is to be as efficient as possible.
For cellular devices –such as the Particle Electron, where data consumption needs to looked at and care for, the two most data efficient protocol are Particle webhooks and TCP.
You can use Ubidots library for Particle devices. It supports both of the aforementioned protocols.
Some considerations to keep in mind:
Using TCP and Ubidots library will allow you, if you choose so, to send each node data as single devices to Ubidots.
On the other hand, connecting through webhooks would force you –given the Electron acts as a gateway to send all data from the nodes to a single device in Ubidots.
Using webhooks makes data more secure as it is encrypted. Ubidots library when TCP is selected sends the data in plain text
I definitely want to send each nodes data as a single device. So if I have 5 nodes with 3 variables each. I would like Ubidots to have 5 devices and each one has their respective 3 variables.
In order to tell the difference between the nodes I want to use the unique MAC (originally received in decimal format like this: 5526146528751682 from the Xbee radios to determine which device should be targeted for sending to Ubidots.
Each node uses a Xbee radio which have a unique MAC printed on them which is represented in HEX like this 0013A20040D2B042. However, when this value is received by the Electron it is in decimal format but I have to use the HEX format. I am struggling on how to convert the decimal back to hex then to a format that works for replacing the Electron device_label with this node ID so that it can be sent to the correct device in Ubidots. Any suggestions would be appreciated.
Hi there, it depends pretty much in the primitive variable type that stores the MAC, but the code below may serve you as reference to convert from HEX to a char array in C++
To complement the idea presented by @jotathebest, here’s a function to convert from a const char* representing the MAC in decimal format to a char [] representing the MAC address in Hex format.
I have done more digging and it turns out the 64-bit MAC address of each end node arrives to the gateway as two separate uint32_t values (Msb and Lsb) of which Msb is the first part of the MAC and Lsb is the second. In order to recreate the MAC in its original HEX value I have two combine Msb and Lsb then go through the process you have shown. I have tried the following with no luck.
I must say I made a mistake in my previous note and to avoid back and forth, the function mentioned in that message doesn’t do what we expect.
Now, under the light of this new information (perhaps would have been useful to share it before), I did another function which receives the MSB and LSB 32 bit unsigned integers, and a char* to store the Hexadecimal representation of the Xbee 64 bit MAC address:
uint32_t msb = 1286656; // For you it would be "uint32_t msb = ioSample.getRemoteAddress64().getMsb();"
uint32_t lsb = 1087549506; // For you it would be "ioSample.getRemoteAddress64().getLsb();"
char* macHexa = (char*) malloc(sizeof(char) * 16);
toHexString(msb, lsb, macHexa2);
Serial.print("MAC in Hex format: ");
Serial.println(macHexa);