Skip to content

Instantly share code, notes, and snippets.

@niektemme
Created July 31, 2015 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niektemme/8c0c08a3444a1ec0ff5f to your computer and use it in GitHub Desktop.
Save niektemme/8c0c08a3444a1ec0ff5f to your computer and use it in GitHub Desktop.
Smart Thermostat Arduino - part XBee send
#include <XBee.h>
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
// create a software serial port for the XBee
SoftwareSerial Serial3(6, 7);
//XBee objects and constants
XBee xbee = XBee();
XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x40B7FB33); //XBee adress of XBee connected to Raspberry PI
// LCD Connection & screen size
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define WIDTH 16
...
//char varaibles for XBseend
char sendValue[10];
//variable for carousell deciding which sensor value to send over xbee to raspberry pi
int sendp = 0;
long previousMillisSend = 0; //previous send
long intervalSend = 100; //interval between xbee sends
...
void setup() {
...
// start display
pinMode(controllPin, OUTPUT);
lcd.begin(WIDTH, 2);
lcd.clear();
lcd.print("Smart Therm");
lcd.setCursor(0,1);
lcd.print("v1.00");
delay(1000);
//Start XBee software serial
Serial3.begin(9600);
xbee.setSerial(Serial3);
}
void loop() {
unsigned long currentMillis = millis();
...
//carousell to send one sensor value over xbee each send interval
if(currentMillis - previousMillisSend > intervalSend) {
previousMillisSend = currentMillis;
if(sendp==0) {
fxbesend("A01_",tempValue);
} else if(sendp==1) {
fxbesend("A02_",sensorValue);
} else if(sendp==2) {
fxbesend("A03_",boilerValue);
} else if(sendp==3) {
fxbesend("A04_",thermistorValue);
} else if(sendp==4) {
fxbesend("A05_",thermistor2Value);
} else if(sendp==5) {
fxbesend("A07_",boilerStat);
}
if(sendp<5) {
sendp = sendp + 1;
} else {
sendp = 0;
}
}
}
//XBee send function
void fxbesend(char fport[4],int fvalue ) {
sprintf(sendValue,"%s%i",fport,fvalue);
ZBTxRequest zbtxt = ZBTxRequest(addr64, (uint8_t *)sendValue, strlen(sendValue));
xbee.send(zbtxt);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment