Page tree
Skip to end of metadata
Go to start of metadata

This documentation explains the steps taken in sending data to UCW platform using cellular-capable micro-controller (micro-controllers with SIM module). We used an example where we sent static data to our platform.

Table of Contents

1.0  Adafruit FONA 32u4 Overview

An overview of the Adafruit FONA 32u4 can be viewed for technical description of this micro-controller.

2.0 Diagram of DHT to FONA 32u4 radio connection

3.0 Implementation

3.1 The GSM switch

Uncomment the appropriate switch in the UCW_Config.h file

UCW_Config
//switches
//#define UCW_BLE_DEVICE      //BLE switch
//#define UCW_ETHERNET_DEVICE //Ethernet switch
#define UCW_GSM_DEVICE        //GSM switch
//#define UCW_LORA_DEVICE     //LORA switch
//#define UCW_WIFI_DEVICE     //WiFi switch

3.2 The Config file

Edit the the config.h file by un-commenting the lines below and providing necessary information. The mobile carrier APN setting information, and token, for authentication, are required here

config.h
#include <UCW_System.h>
 
/************************ UCW Platform Config *******************************/
// Configuration of the connection string to the UCW Platform.
// for WiFi/GSM/Ethernet connections
static UCWConfig cfg = {
  .host = UCW_API_HOST,
  .port = UCW_API_PORT,
  .isSecuredConnection = false,
  .useMqtt = false,
  .mqttUser = UCW_MQTT_USER,
  .mqttPassword = UCW_MQTT_PASS,
  .token = "your_token"
};

/**************************** GSM************************************/
//APN settings of mobile carrier
const char apn[]PROGMEM = "your_apn";
const char username[]PROGMEM = "your_username";
const char password[]PROGMEM = "your_password";

// uncomment the following two lines for GSM,
#include "UCW_Mobile.h"
UCW_Mobile ucw(&cfg, apn, username, password);

3.3 Library

Include the config.h file mentioned in section 3.1 above and any library that might be needed. In this example, we do not need any additional library

library
#include "config.h"

3.4  deviceID and data-stream name 

These variables are used to uniquely identify the FONA device and sensor data transmitted our platform. The DEVICE_ID is generated by the UCW platform and also serves as a form of authentication of the user. 

#define DEVICE_ID "your_device_id"
#define DATA_STREAM "your_dataStream_name"

3.5 connect, networkStatus, and printNetworkInfo methods

3.5.1 connect method

This method is called in the setup() section of the arduino code. It initialises the FONA module, ensures the SIM is connected to the network,  and connects the device to the GPRS network of the mobile carrier. FONA 800 device type supports 2G cellular network. That means it supports GPRS, but not GPS. The GPS support was included in FONA 808. FONA 3G supports 3G networks. 

connect()
ucw.connect();
3.5.2 networkStatus method

This checks the status of the attempted connection between the FONA and the cellular network. In this example, it is used in a loop to ensure the the device is connected to the network.

networkStatus
while (ucw.networkStatus() != UCW_NET_CONNECTED) {
  Serial.print(".");
  delay(500);
}
3.5.3 printNetworkInfo  method

Relevant device and network information such as RSSI, firmware version, and SIM CCID are displayed on the serial monitor

printNetworkInfo
ucw.printNetworkInfo();

3.6  The sys method

The sys method reconfirms that the FONA's GPS/GPRS connection is still valid. If connection is lost, it performs a reset by disabling and re-enabling the connection. This is the first method called in the loop() section of the arduino code.

sys()
ucw.sys();

3.7 The sendData method

This method takes three parameters: the device ID, datastream name, and payload . The device ID and datastream name are as earlier described in Section 3.4. The payload refers to the JSON containing the data to be sent to our server. The sendData method transfers the payload to our platform via cellular/GSM network

sendData()
String data = "{\"temperature\": 22, \"humidity\": 43}";
ucw.sendData(DEVICE_ID, DATA_STREAM, data);


The full example can be found here.

  • No labels