Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Tadeas Dvoracek
Published © GPL3+

Sigfox to Cayenne

Add Sigfox device to Cayenne.

IntermediateShowcase (no instructions)1 hour3,118
Sigfox to Cayenne

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
Wisol SFM10R1
×1
Level Shifter Board
SparkFun Level Shifter Board
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Sigfox
Sigfox
Cayenne
myDevices Cayenne
Node-RED
Node-RED

Story

Read more

Schematics

Schematics

Code

Cayenne-Sigfox-DHT11

Arduino
#include <Wire.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT_Unified dht(DHTPIN, DHTTYPE);

#define sigfox Serial1

int tem;
int hum;

void setup() {
  Serial.begin(9600);
  sigfox.begin(9600);
  dht.begin();
  sensor_t sensor;
  pinMode(13, OUTPUT);
  }

void loop() {
  while (Serial.available()) {
    char c = Serial.read();
    if (c == '1') {
      if (sendMessage()) {
        Serial.println("Message sent successfully!");
      }
      else {
        Serial.println("The message was not sent!");
      }
    }
  }

  sensors_event_t event;  
  dht.temperature().getEvent(&event);
  tem = 100 * event.temperature;
  dht.humidity().getEvent(&event);
  hum = event.relative_humidity;
  
  Serial.println(tem);
  Serial.println(hum);
  delay(2000);
}

bool sendMessage() {
  bool retval = false;
  digitalWrite(13, HIGH);
  uint8_t message[4];
  long start = millis();
  char hexBajt[3];

  memcpy(&message[0], &tem, 2);
  memcpy(&message[2], &hum, 2);
  
  Serial.println("Sending message...");
  sigfox.print("AT$SF=");
  for (int i = 0; i < sizeof(message); i++) {
    sprintf(hexBajt, "%02X", message[i]);
    sigfox.print(hexBajt); 
    }
  sigfox.print("\r");
  while (!sigfox.available()) {
    if ((millis() - start) > 30000) {
      digitalWrite(13, LOW);
      return false;
    }
  }
  while (sigfox.available()) {
    digitalWrite(13, LOW);
    char answer = sigfox.read();
    if (answer == 'O') retval = true;
  }
  return retval;
}

Node red flows

JavaScript
[{"id":"2ee8bab9.a6b926","type":"http request","z":"13eb0657.a1aa1a","name":"","method":"GET","ret":"obj","url":"https://APIlogin:APIpassword@backend.sigfox.com/api/devices/DeviceID/messages?limit=1","tls":"","x":282.2221984863281,"y":311.111083984375,"wires":[["94d91df6.f903b"]]},{"id":"ca6dcf82.86521","type":"inject","z":"13eb0657.a1aa1a","name":"","topic":"","payload":"1","payloadType":"str","repeat":"2","crontab":"","once":false,"x":202.55557250976562,"y":404.66662979125977,"wires":[["2ee8bab9.a6b926"]]},{"id":"94d91df6.f903b","type":"function","z":"13eb0657.a1aa1a","name":"Get data","func":"msg.payload = msg.payload.data[0].data;\nreturn msg;","outputs":1,"noerr":0,"x":439.6666564941406,"y":310.99996185302734,"wires":[["5e62006e.2ebd9","dac1c829.491a18"]]},{"id":"dac1c829.491a18","type":"function","z":"13eb0657.a1aa1a","name":"Temperature","func":"i = msg.payload.slice(0, 4);\na = i.slice(0, 2);\nb = i.slice(2, 4);\nc = b + a\nd = parseInt(c, 16) / 100;\nmsg.payload = d.toString();\nreturn msg;\n","outputs":"1","noerr":0,"x":602.9999389648438,"y":312.3333215713501,"wires":[["d1e922d5.e738","97f26c37.6da58"]]},{"id":"5e62006e.2ebd9","type":"function","z":"13eb0657.a1aa1a","name":"Humidity","func":"i = msg.payload.slice(4, 8);\na = i.slice(0, 2);\nb = i.slice(2, 4);\nc = b + a\nd = parseInt(c, 16);\nmsg.payload = d.toString();\nreturn msg;","outputs":1,"noerr":0,"x":613.8888092041016,"y":366.3333320617676,"wires":[["d1e922d5.e738","a3c2b6b2.3565d8"]]},{"id":"d1e922d5.e738","type":"debug","z":"13eb0657.a1aa1a","name":"","active":false,"console":"false","complete":"false","x":842.0000152587891,"y":267.6666450500488,"wires":[]},{"id":"97f26c37.6da58","type":"mqtt out","z":"13eb0657.a1aa1a","name":"","topic":"v1/MQTTusername/things/ClientID/data/1","qos":"0","retain":"","broker":"","x":922.4443969726562,"y":310.4444236755371,"wires":[]},{"id":"a3c2b6b2.3565d8","type":"mqtt out","z":"13eb0657.a1aa1a","name":"","topic":"v1/MQTTusername/things/ClientID/data/2","qos":"0","retain":"","broker":"","x":925.1109924316406,"y":366.4443588256836,"wires":[]},{"id":"53036e03.74a74","type":"comment","z":"13eb0657.a1aa1a","name":"Setup - http request","info":"You must enter your own:\n\n-API login\n-API password\n-Device ID","x":251.11111450195312,"y":264.4444465637207,"wires":[]}]

Credits

Tadeas Dvoracek

Tadeas Dvoracek

10 projects • 41 followers

Comments