The Thinxtra devkit Xkit boasts a full suite of features and accessories to empower anyone to develop an IoT solution. Perfect for start-ups, DIY home IoT projects, and academic research, this kit has everything you need to hit the ground running using the Sigfox's global connection network.

In this article, you will learn how to program an Thinxtra Xkit for an IoT application that takes and sends temperature readings via Sigfox, whenever motion is detected.

Requirements

Setup

1.- Register your devkit on the Sigfox backend portal; reference to the video below to learn more and register your Thinxtra Xkit Device on Sigfox backend.

2.- Download the Thinxtra repository to receive the required libraries. The libraries should be copied to the location with Arduino libraries.

3.- Once the libraries are saved in the Arduino IDE, copy and paste the code below to the IDE:

/*
  SimpleProgram.ino - Demo application for Xkit with Arduino board
  Version 1.0
  Created by Gildas Seimbille, Thinxtra Solution Pty.
  May 20, 2017.
  Using Adafruit_BMP280_Library and Adafruit_MMA8451_Library
  Copyright (c) 2012, Adafruit Industries
  Modified by Thomas Ho
  Released into the public domain.
*/

// Include librairies
#include <WISOL.h>
#include <Tsensors.h>
#include <Wire.h>
#include <math.h>

Isigfox *Isigfox = new WISOL();
Tsensors *tSensors = new Tsensors();

// Init function
void setup() {
  Wire.begin();
  Wire.setClock(100000);

  // Init serial connection between Arduino and Modem
  Serial.begin(9600);

  // WISOL modem test
  Isigfox->initSigfox();
  Isigfox->testComms();

  // Init sensors on Thinxtra Module
  tSensors->initSensors();

  // Init an interruption on the button of the Xkit
  tSensors->setButton(buttonIR);
}

// Infinite loop of the program
void loop() {
  float axeX = getAxeX();
  Serial.print("Check Axe X: "); Serial.println(axeX);
  if (axeX <= -0.4 or axeX >= 0.4) {
    // Get Temperature
    float temp = getTemp();
    // Send Temperature to Sigfox
    Send_Pload((const char*)&temp, sizeof(temp));
    // Wait 20s
    delay(20000);
  }
  delay(1000);
}

// Return the acceleration on Axe X
float getAxeX() {
  acceleration_xyz *xyz_g;

  xyz_g = (acceleration_xyz *)malloc(sizeof(acceleration_xyz));
  tSensors->getAccXYZ(xyz_g);

  float axeX = (float)xyz_g->x_g;
  free(xyz_g);

  return axeX;
}

// Get the temperature
float getTemp() {
  float temp = round(tSensors->getTemp() * 10) / 10.0;
  Serial.print("Sending Temp: "); Serial.println(temp);

  return temp;
}

// SendPayload Function => Send messages to the Sigfox Network
void Send_Pload(uint8_t *sendData, int len) {
  recvMsg *RecvMsg;

  RecvMsg = (recvMsg *)malloc(sizeof(recvMsg));
  Isigfox->sendPayload(sendData, len, 0, RecvMsg);
  for (int i = 0; i < RecvMsg->len; i++) {
    Serial.print(RecvMsg->inData[i]);
  }
  Serial.println("");
  free(RecvMsg);
}

// Button Interruption
void buttonIR(){
    float temp = getTemp();
    Send_Pload((const char*)&temp, sizeof(temp));
}

3a.- Next, compile the code into the Arduino UNO
NOTE:  remove the Thinxtra shield to be able to compile the code properly. 

3b.- Connect the board to the computer, then select the Arduino UNO as board from Tools > Boards, also select the Port COM of the board from Tools > Port.

3c.-  Verify your code in the Arduino IDE by choosing the "Check Mark" icon in the top left of the IDE. Once the code is verified, you will receive a "Done compiling" message in the Arduino IDE.

3d.- Upload the code into the Arduino UNO by choose the "right-arrow" icon beside the check mark icon. Once uploaded, you will receive a "Done uploading" message in the Arduino IDE.

4.- Connect the Thinxtra shield with the Arduino UNO once your device is compiled and reset the board by pressing the red button on the Arduino UNO

5.- The code above sends temperature value to Sigfox every time the board detects a movement. To visualize the the data sent, open the serial monitor of the Arduino IDE. You can also verify the messages via Sigfox's backend by selecting the ID of the Thinxtra device from the device list.

Next, select the "message" option from the left menu:

5.- With the messages begin received by Sigfox's backend, it's now time to setup a pre-configured callback to display your data with Ubidots. Reference the article below to setup an Ubidots callback and learn more about the configurations:

With the code from the article above, set the parameters below into the callback configuration to be able to handle this Sigfox data with the callback properly:

  • Type: DATA - UPLINK
  • Channel: URL
  • Custom payload config: temperature::float:32:little-endian 
  • Url pattern: 
https://things.ubidots.com/api/v1.6/devices/{device}/?token={Put_Your_Ubidots_TOKEN_here}
  • Use HTTP method: POST
  • Content Type: application/json
  • Body:
{
  "snr" : "{snr}",
  "avgSnr" : "{avgSnr}",
  "rssi" : "{rssi}",
  "position":{"value":0,"context":{"lat":"{lat}","lng":"{lng}"}},
  "temperature" : {"value":"{customData#temperature}"}

Once you've entered all the parameters required, verify your callback looks similar to that of below:

IMPORTANT DEPLOYMENT NOTE:  Ubidots and Sigfox communicate via either URL or Batch URL (used for large deployments). This tutorial explains the standard URL channel. If you have a large scale sensor network, please contact sales@ubidots.com to receive additional information for Batch URL integrations.

6.-  With the above quick steps, your device is now integrated with Ubidots and sending data whenever the the Thinxtra Xkit senses movement. To visualize your data, sign into your Ubidots account and verify the device just created with the Device ID and see and manipulate the collected data as needed.

In this tutorial we describe taking temperature readings based on movement. When other parameters are assigned into the callback body like the rssi, snr, avgSnr, and position, these too will be recorded or assigned when built by the developer.

Pro Tip: Ubidots let you modify the name of the device with a friendly one when needed, if you don't know how to modify it reference to the article below:

IMPORTANT NOTE: If you desire to returns device messages where at least one callback has failed, reference to the Sigfox API to know how to implement it.

Result

Now it is time to create a dashboard to control and manage the variables of your Sigfox device. To learn more about Ubidots widgets and events, check out these video tutorials.

Did this answer your question?