Using the Rest API versus socket

Hi,

I’ve been looking at the embedded api documentation
thanks to @Maiky and have a couple questions.

  1. We need to use a different device api key for every single different board with a different SIM, but that is really difficult. Is there a way of doing that where you only need one single api key, and it still registers which SIM sent the data? I don’t want to have to write 1000 different versions of code for an application firmware release if there is a simpler way of get all devices to connect when they need to.

  2. I was looking at the REST api documentation, because perhaps that might work with one master api key to use across all devices, but all the examples look like you send a json as an sms to the hologram cloud. Any tips on using that? I got a little confused. Does that incur an SMS charge?

I want to do what makes most sense for having thousands of sensors out in the field reporting.

Thanks!

Some answers:

  1. See Device key - Possible to group? pretty much the same question you have!
  2. Using the REST API to send data over cellular will rack up a lot more data usage (overhead) than you want. Hologram has a blog post on this: Hologram.io Data Usage Breakdown. In the IoT space, every byte counts —… | by Ross Hettel | Hologram.io | Medium also see Data Usage and more - #8 . You don’t need to use SMS with the REST API it is all over the internet.

Note although it may be easier to use a shared device key You should avoid it for security reasons. If someone compromises one of your devices and gets that universal key your only choice is to kill ALL of your devices by disabling that one key or let them abuse your key. With individual keys you can disable the one compromised key and leave your remaining devices active.

I had a similar concern with a fleet of devices as you and went with the SMS route I describe in the linked community post. I have played and got working sending SMS, sending config information to embedded device after programming (ie Flash firmware, on first firmware boot send config information that in writes to flash storage, ship product), and using cloud messaging in a similar way as SMS.

1 Like

Hi @AndrewGifft! Thank you for the info you shared on this and the other community post.

I am also wanting to work with a number of devices. Would you mind sharing an example of how to get the device key from the SMS? Or possibly a link to documentation.
If it matters, I’m using a PyCom GPy.
Thank you for your help!

I haven’t found a public resource demonstrating this and I cant share my own code but neither would be that helpful as a lot of it depends on your end device and your code base. The “Device key - Possible to group?” post should give you basically everything you need. For a moderate number of devices (<=100) you can use the hologram dashboard to send an SMS to your device.

Part 1: Send SMS to device
The contents of the SMS can be anything and you will have to decide a standard, one example is shown below assuming Hologram assigned this device “DeviceID: 12345” and “Device Key: 98765”:

Part 2: Receive and parse SMS on device
This part depends on your code and is probably more appropriate to go to PyCom’s forums if you need help asking “How do I configure the GPy to receive SMS and read in the received message” Once you receive the message you can store the whole thing to non volatile memory (something like Storing files on the micro:bit : Help & Support)

Now whenever your program loads, or when you want to send a cloud message you read this stored data and know anything after the “ID=” and up to “Key=” is the device ID, and anything after “Key=” is the device key.

Note this will cost you $0.19 per SMS but that should only be required once per device. But if you are spending $50 on the GPy a total cost of $50.19 to have a common code base is probably worth it.

1 Like

Thank you Andrew! This was immensely helpful.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.