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

In this example, we show the procedure for sending static data to our platform using Adafruit Ethernet FeatherWing.

Table of Contents

1.0  Adafruit Ethernet FeatherWing Overview

An overview of the Adafruit Ethernet FeatherWing can be viewed for technical description of this micro-controller.

2.0 Implementation

2.1 The Ethernet 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

2.2 The Config file

Edit the the config.h file by un-commenting the lines below and providing necessary information.

config.h
#include <UCW_System.h>

/************************ UCW Platform Config *******************************/

// Configuration of the connection string to the UCW Platform.
// for WiFi/GSM/Ethernet connections only
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"
};

/**************************** Ethernet ************************************/
/*
  The UCW_Ethernet client will work with the following boards:
    - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
 */

// Enter a MAC address for your controller below.
byte mac_add[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};


// Provide static IP address if not using DHCP
IPAddress ip_add(0,0,0,0);

// Uncomment the following two lines for ethernet,
#include "UCW_Ethernet.h"
UCW_Ethernet ucw(&cfg, mac_add, ip_add);

You are expected to provide the MAC address of the Ethernet shield. Static IP address can also be used if the dynamic allocation of IP address is unavailable.

The MAC address and IP address should be of data type byte and IPAddress respectively.

2.3  Device ID and Data stream name 

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

#define DEVICE_ID   "your_deviceID"
#define DATA_STREAM "data-test"

2.4 The connect method

This method is called in the setup() section of the sketch code. It initializes the Ethernet module. The MAC address is used to start Ethernet connection. If DHCP fails, the static IP address provided is used.

connect()
ucw.connect();

2.5  Printing network information

The printNetworkInfo() method displays relevant information of the connected network and displays same on the serial monitor. 

printNetworkInfo
ucw.printNetworkInfo();

2.6  The sys method

The sys method reconfirms that the connection to our server is still active, and if lost, re-establishes connection. This is done in the loop() section of the sketch code.

sys()
ucw.sys();

2.7 The readData method

In this example, we sent a fixed data, a JSON string, to send to our server

Read data
String data = "{\"temperature\": 22, \"humidity\": 43}";

2.8 The sendData method

This method takes three string parameters: device ID, datastream name, and payload. In this example, we used DEVICE_IDDATA_STREAM and data as parameters for the sendData method

sendData()
ucw.sendData(DEVICE_ID, DATA_STREAM, data);


The full example can be found here.

  • No labels