Sunday, March 18, 2018

NB-IoT with Inzpire

March 18, 2018 Posted by Akalanka , , 2 comments

Maintaining communication with remote devices is always a challenge in IoT. Building a IoT solution is always a new exercise because the types of hardware and protocols keep getting updated periodically. A good example is the Constrained Application Protocol (CoAP) which rose to popularity with small devices coming into the picture in Internet of Things. Today we will see how Inzpire can minimize the hassle of connecting your NB-IoT device with your application server.

Why CoAP?
Not all protocols are made the same way. CoAP is a very lightweight protocol optimized for low bandwidth networks. Unlike our good old HTTP which has been a reliable workhorse for more than 90% of our digital interactions with a very verbose protocol, CoAP has a compact packet format based on a binary protocol. Being an application layer protocol it relies on UDP transport for end to end delivery. However since guaranteed delivery is not a thing for UDP, CoAP implements its own simple stop-and-wait type error recovery and congestion control mechanism. If you know about the more sophisticated features offered by TCP such as adaptive flow control, think of CoAP like its slow cousin. But CoAP thrives in a resource constrained environment both on the network and device ends which gives it an edge over TCP in most narrow band applications. In tests we have seen that when operating at the coverage edge with NB-IoT, CoAP request with a 10 byte payload takes less than 3 seconds while a simple HTTP GET request takes in excess of 30 seconds (Yes you saw that right, its 30s, crazy stuff happen when you push the poor modem to the limit). I was initially skeptical on the effectiveness of CoAP, but the results of the above experiment made me think otherwise.

Inzpire to the rescue
Using CoAP comes with its own set of cons. A major one being the lack of experience needed to setup and maintain a CoAP server for device communication. Inzpire NB-IoT solves this problem for you by acting as gateway to forward CoAP messaging to and from HTTP. If you are familiar with how SMS and Voice works in Inzpire you will notice many similarities.


In this article we will see how you can connect your Banana Pi with a BC95 NB-IoT modem to your application through Inzpire NB-IoT. For more info on Banana Pi and NB-IoT refer the previous posts in this blog.

Step 1: Setup an HTTP/MQTT endpoint for device to communicate

HTTP method

You should have a HTTP web server running at a public location for handling up link messages from the device. Once a call is received by your short code or long number an HTTP request will be made from the Inzpire voice server to this server. The URL of this service should be entered in the callback URL in the next step when provisioning a NB-IoT device. The request will be a HTTP POST with the following parameters in a JSON formatted payload in the body
  • deviceId: This is the IMEI of the NB-IoT modem
  • payload:
    • type: data type is Buffer by default
    • data: data payload sent by the device as an array
MQTT method

If you are opting for the MQTT integration, you should have a public MQTT broker for this step. You will receive a publish from the device to the topic that you will provide in the next step. If you are subscribed to that topic with your own favorite MQTT client, you will be able to receive the message.

Step 2: Provision your Banana Pi in Inzpire

Provisioning an NB-IoT device in Inzpire is made extremely simple with a single SMS. 
  • HTTP Method:
    • Send NBReg<Space><IMEI of your Banana PI><space><Callback URL> to 77001
  • MQTT Method:
    • Send NBReg<Space><IMEI of your Banana PI><space><MQTT Broker URL><space><MQTT topic> to 77001
  • You will get a USSD prompt indicating that you will be charged a subscription fee for the service
  • Enter S in the USSD prompt and hit send
  • You will receive an SMS with 'Device registered successfully' with a device key.
Step 3: Connect your Banana-Pi , fire up Arduino IDE and start coding

Once your device is registered, simply call the functions related to messaging via CDP in the BC95-Arduino library at https://gitlab.com/akalankadesilva/BC95-Arduino to send messages and receive messages. All the messages that the device sends will be sent as HTTP POST requests to your callback URL.





2 comments:

  1. Does the APN need to be set in this code ? and if so what is mobitel's APN?

    ReplyDelete
  2. Especially for this, we connect for you a listing of the best and 카지노사이트 추천 most trusted providers of internet video games for playing initiatives. If you need to win actual money slots, you should to} know what to look for. Sifting via 100s of video games for the best RTP slots is probably something you are not wanting to do. Below are the top 10 highest-paying online slots in the US right now.

    ReplyDelete