Example Arduino Sketch


You will need to edit the example sketches provided, as each gateway’s device identification number must be declared.
#include
#include


//Gateway Parameters (ID = GATWAY_ID, ChannelMask = 0xFFFFFFFF (all channels allowed), I2C Address 0x30, DataReady = pin D5, Reset = Pin D6)
#define GATEWAY_ID “T08KN4” //<>
#define GATEWAY_CHANNELS 0xFFFFFFFF // All Channels
#define GATEWAY_ADDRESS 0x30 //<>
#define GATEWAY_PINDATAREADY 5 //<>
#define GATEWAY_PINRESET 6 //<>


#define SENSOR_ID “T08L10” //>


/**********************************************************************************
*Global Variables
*********************************************************************************/
TartsGateway gateway(GATEWAY_ID, GATEWAY_CHANNELS, GATEWAY_ADDRESS, GATEWAY_PINDATAREADY, GATEWAY_PINRESET);
TartsTemperature sensor(SENSOR_ID);


/**********************************************************************************
*Tarts Events
*********************************************************************************/
void onGatewayMessageEvent(const char* gatewayID, int stringID){
//print out the gateway message
Serial.print(“GW[“);
Serial.print(gatewayID);
Serial.print(“]: “);
Serial.print(stringID);


if(stringID == 4) Serial.println(” – OFF”);
else if(stringID == 10){
Serial.print(” – ACTIVE, Channel: “);
Serial.println(Tarts.FindGateway(gatewayID)->getOperatingChannel());
}
else Serial.println();
}


void onSensorMessageEvent(SensorMessage* msgconst char* id, Datum* datumList, int count){
Serial.print(“SENSOR[“);
Serial.print(msg->IDid);
Serial.print(“]: “);
Serial.print(“RSSI: “);
Serial.print(msg->RSSI);
Serial.print(” dBm, Battery Voltage: “);
Serial.print(msg->BatteryVoltage/100);
Serial.print(‘.’);
Serial.print(msg->BatteryVoltage%100);
Serial.print(” VDC, Data: “);
for(int i=0; iDatumCount; i++){
if(i != 0) Serial.print(” || “);
Serial.print(msg->DatumList[i].Name);
Serial.print(” | “);
Serial.print(msg->DatumList[i].Value);
Serial.print(” | “);
Serial.print(msg->DatumList[i].FormattedValue);
} for(int i=0; i<count; i++){
if(i != 0) Serial.print(” || “);
Serial.print(datumList[i].Name);
Serial.print(” | “);
Serial.print(datumList[i].Value);
Serial.print(” | “);
Serial.print(datumList[i].FormattedValue);
}
Serial.println(“”);
}


/**********************************************************************************
* Arduino setup and loop code
*********************************************************************************/
void setup() {
//Prepare output for testing and results
Serial.begin(9600);
while (!Serial) ;
Serial.print(“TARTs Basic application started…”);


//Prepare all the call-back functions
Tarts.RegisterEvent_GatewayMessage(onGatewayMessageEvent);
Tarts.RegisterEvent_SensorMessage(onSensorMessageEvent);
Serial.println(“all event handlers registered.”);


if(!Tarts.RegisterGateway(&gateway)){
Serial.println(“Gateway Registration Failed!”);
while(1);
}


//Lastly Register All Sensors
while(!Tarts.RegisterSensor(GATEWAY_ID, &sensor)){
Serial.println(“Sensor Registration Failed!”);
while(1);
}
}


void loop() {
Tarts.Process();
delay(100);
}