Basic UDP Communication Tutorial for Sixfab Arduino Cellular IoT Application Shield

Saeed • 4 Sep 2018
General
Ardu CIoT img3

Related Blog Post

Subscribe to our newsletter

After the our first tutorial on Sixfab Arduino Cellular IoT Application Shield in which we mentioned monitoring sensors only. Since the shield have feature of LTE-M & NB-IoT & eGPRS, we will demonstrate each of them. In this tutorial we are going to show the UDP communication with the mentioned shield. 

Router Setup

  1. Login to you routers configurations, by going to 192.168.1.1(generally this is the address for router configurations, might change for some router) from your Internet browser and login with your own credentials.
    2
  2. Now scroll down at Basic Status page to find your IP address of your connection (which is mentioned as dsl_internet in our case). We will need it later.3a
  3. Now click on Forwarding form the option list and then click Virtual Server.
  4. Then click on Add New, which will take you to the following screen. Now fill up Service Port(as desired, in our case it is 5000), IP Address(It is IP Address of your Computer/Laptop. Check the note below if you don’t know how to obtain your IP Address) and select Protocol(as UDP). Click Save.>5a
    ** Note: Open your terminal and run ifconfig command to obtain your IP Address. This is applicable for linux users. Windows user can type ipconfig in cmd command.

Arduino Library Setup and Coding

  1. Download Zip or clone the Library from our github repo. (Personally for Arduino I like to download zip)
    For cloning you may type the following command in your terminal.

    git clone https://github.com/sixfab/Sixfab_Arduino_CellularIoT_Library.git

     

  2. Now open your Arduino IDEardu_ciot_code1
  3. To add the library, from top menu go to Sketch > Include Library > Add ZIP Library ardu_ciot_code2
  4. Find your location of downloaded library and select the zip file / folder in case of cloning. Then click OK ardu_ciot_code3
  5. Once you add the library, you will be able to find the available examples for your Cellular IoT Application Shield. Lets open our first example from  File > Examples > Sixfab_CellularIoT > sensorTest ardu_ciot_code7UDP
  6. This bring up the following code. Here find the following lines ans replace xx.xx.xx.xx and xxxx with your routers IP and your selected port respectively.
    char your_ip[] = "xx.xx.xx.xx"
    char your_port[] = "xxxx"

    ardu_ciot_code8udp

  7. Now plug the SIM card and antenna to the shield as follows. (only LTE port of antenna is enough to connect for this tutorial). ardu_ciot_img4
  8. Attach the Shield to the Arduino and connect the Arduino to your laptop/PC.ardu_ciot_img5
  9.  Confirm wither the selected port is correct or not from Tools > Portardu_ciot_code9
  10. Open a terminal and type the following command to listen the UDP data.
    netcat -ul -p5000

    ardu_ciot_code10udp

  11. Upload the code to your Arduino and open the Serial Monitor. Then you will observe the following which shows SEND OK at the end if it works fine. ardu_ciot_code11udp
  12. On the terminal we can see a string “Hello World!” which was sent over UDP.ardu_ciot_code12udp

 

If we observe the code then we will be able to see that sendSataUDP() is used to send data over UDP.

While

  • init() is to initiate the unit,
  • setIPAddress() sets the IP address of the router,
  • setPort() sets the port selected in port forwarding,
  • setGSMBand() sets desired band (Possible parameters are GSM_900, LTE_B5, LTE_B20),
  • startUDPService() starts the service for UDP communication.

So the library has made it further easy to code the shield.

We will be coming up with TCP Communication in our next tutorial.