Skip to content

Instantly share code, notes, and snippets.

@mariacarlinahernandez
Created August 14, 2017 18:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariacarlinahernandez/0dc05b21e85e3332d917fb4d68ac7eb2 to your computer and use it in GitHub Desktop.
Save mariacarlinahernandez/0dc05b21e85e3332d917fb4d68ac7eb2 to your computer and use it in GitHub Desktop.
// 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));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment