Das OpenKontrol Gateway ist ein optimales Internet-Gateway um meine Sensordaten an die IoT-Plattform Cosm zu senden.

Im nachfolgenden Beispiel werden die Daten von Node 13 an Cosm gesendet. Dabei werden 2 Datenstreams, Temperatur und Batteriespannung übertragen.

Das Senden der Daten an Cosm wird mit der Bibliothek ERxPachube realisiert.

Auf dem Arduino-basierenden Gateway zeigt Pin 17 mittels Status-LED den Empfang von Daten an.

//
// OpenKontrol Gateway - sending rf data to COSM
// Date: 10.05.13
// www.arduino-praxis.ch

#include <SPI.h>
#include <Ethernet.h>
#include <JeeLib.h>
#include <Arduino.h>
#include <HardwareSerial.h>
#include <ERxPachube.h>

// Ethernet
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAD };
byte ip[] = { 10, 0, 1, 101 };
byte gateway[] = { 10, 0, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };

// Cosm API-Key
#define PACHUBE_API_KEY	"YourAPIKey"
// Cosm Feed ID
#define PACHUBE_FEED_ID YOURFEEDID

// Status senden 1:OK
int sendenStatus = 0;

ERxPachubeDataOut dataout(PACHUBE_API_KEY, PACHUBE_FEED_ID);

void PrintDataStream(const ERxPachube& pachube);

// Fixed RF12 settings
#define MYNODE 3            //node ID of the receiever
#define freq RF12_433MHZ     //frequency
#define group 210            //network group

 typedef struct {
          int rxD;              // sensor value
          int supplyV;          // tx voltage
 } Payload;
 Payload rx;

int nodeID;

int value;
int millivolts;

// Data received
const int LEDpin=17;

void setup()
{
  Serial.begin(9600);
  rf12_initialize(MYNODE, freq,group); // Initialise the RFM12B
  Ethernet.begin(mac, ip);

  // 2 Datenstreams Sensor Node 13
  // Temp Inside
  dataout.addData(0);
  // Battery
  dataout.addData(1);

  // Daten empfangen
  pinMode(LEDpin, OUTPUT);
  digitalWrite(LEDpin,HIGH);

  Serial.println("TinyTX Simple Receive Example");
  Serial.println("-----------------------------");
  Serial.println("Waiting for data");
  Serial.println(" ");
}

void loop()
{
  if (rf12_recvDone() && rf12_crc == 0 && (rf12_hdr & RF12_HDR_CTL) == 0) {
  nodeID = rf12_hdr & 0x1F;  // get node ID
  rx = *(Payload*) rf12_data;
  value = rx.rxD;
  millivolts = rx.supplyV;
  Serial.println("Received a packet:");
  Serial.print("From Node: ");
  Serial.println(nodeID);
  Serial.print("Value: ");
  Serial.println(value);
  Serial.print("TX Millivolts: ");
  Serial.println(millivolts);
  Serial.println("--------------------");
  if (nodeID== 13)
  {
    digitalWrite(LEDpin,HIGH);
    sendenStatus=1;
  }
 }

  // Daten an Cosm senden
  if (sendenStatus == 1) {
  Serial.println("Sendig Data to COSM");
  float data0 = value;
  float data1 = millivolts;
  data0=data0/100;
  dataout.updateData(0, data0);
  dataout.updateData(1, data1);

  // Show Status
  int status = dataout.updatePachube();
  Serial.print("Status: ");
  Serial.println(status);

  // Daten senden
  PrintDataStream(dataout);

  sendenStatus=0;
  // turn off status LED to indicate
  // succesful data receive and online posting
  digitalWrite(LEDpin,LOW);
  }

}

void PrintDataStream(const ERxPachube& pachube)
{
  unsigned int count = pachube.countDatastreams();
  Serial.print("data count=> ");
  Serial.println(count);

  Serial.println(",");
  for(unsigned int i = 0; i < count; i++)
  {
    Serial.print(pachube.getIdByIndex(i));
    Serial.print(",");
    Serial.print(pachube.getValueByIndex(i));
    Serial.println();
  }
}
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

No Responses to “OpenKontrol Gateway – RF Daten senden an COSM”  

  1. No Comments

Leave a Reply



Kategorien