In this project, I will hook up a button to my Arudino UNO. When the button is pressed, it will send a message through the Sigfox backend to my virtual server, and then finally as a notification to my mobile phone.
Objective
Low Power Wide Area Networks (LPWAN) are making IoT engineers all over the world excited. Sigfox is an LPWAN. The ability for Sigfox to send messages without using WIFI or the 4G network, as well as the limitation of 140 uplink messages a day with payload of 12 bytes per message is a complete shift in paradigm for what you could and couldn’t do with it. When I first received my Sigfox developer shield from Unabiz, I quickly went ahead to hook up several sensors to send message to the Sigfox backend.
As with many of my projects, Zoe becomes the business case. In short, this is what it does:
- Zoe’s in school and figured that she forgot pocket money. Zoe doesn’t own a mobile phone but still needs to call me for help. She presses for help on Zoe Helper.
- A message is transmitted to the Sigfox network, which then perform a call-back to my web API. The web API triggers a notification on my OneSignal.com Application which I have configured to connect to my Google FireBase account.
- My mobile app receives the notification from OneSignal.com and I note that Zoe needs help.
This is how the SOS device look like. It’s too big now, but it’s a prototype so I can live with this.
Messaging
Messages are routed through several different platforms in this project. For clarity, I have illustrated it as follows:
Why had I routed my message from jacksonng.org to OneSignal and then to Firebase instead of routing directing from jacksonn.org to Firebase? I am catering for use cases where the message may not be received on my mobile device, but an iPhone, a website or any other recipient that OneSignal supports but Google Firebase doesn’t.
Parts
This project is divided into 3 parts and will be documented in a series of 3 blog posts.
- Part 1: Connecting Unabiz Shield, Arduino UNO and the SOS button and configuring backend.sigfox.com to send the call-back to my virtual server.
- Part 2: Developing the web API on my virtual server to receive the callback, decode the message, and send it to OneSignal.com.
- Part 3: Receiving the notification from OneSignal.com and showing it on my mobile device.
So on to part 1.
Fritzing
This isn’t an accurate depiction of the prototype because it does not show the UnaShield. No one has created a part for the UnaShield on Fritzing and I am too lazy to do it. Please imagine that there’s an UnaShield stacked on the Arduino UNO when you read this. There’s nothing exciting here really, just a button hooked up to an UNO.
Something to note though, D4 and D5 pins of the Arduino are used by the UART interface on the UnaShield. So don’t stick any wires here. Every other pins are fine.
Codes
Add the Sigfox library to your Arduino IDE.
Codes are in Github here.
And here are the most important bits. These lines are executed when Zoe presses the SOS button.
Message msg(transceiver); //prepare message to send
/*
Here are all the 12 bytes you can send at once,
As an example, I maxed out all 12 bytes.
Each field is 4 bytes, "d1" is the key, "zoe" is the data.
You really need to send just 4 bytes to say that a button is pressed.
I did this so that I can explore decoding all 12 bytes at once.
*/
msg.addField("d1", "zoe");
msg.addField("d2", "ned");
msg.addField("d3", "hep");
msg.send();
Sigfox Backend
Login to the Sigfox Backend using the same credentials that you used to register for your Sigfox shield. Go to Device > Click on the device type, followed by CALLBACKS.
Edit the URL to configure what you wish to send to your web API. In my case, these are what I am sending to newnotifications.php on my server:
- The sending UnaShield’s device ID – deviceid={device}
- The 12 bytes message – message={data}
http://jacksonng.org/sigfox/newnotifications.php?message={data}&deviceid={device}
Finally, press the button on the prototype and observe new messages appearing under Device > Click on your device’s ID > Messages.
What’s Next
Part 2 of this project documentation will demonstrate what happens when the web server receives this callback from Sigfox backend.
Photo by Felipe Faria on Unsplash