/* Transmission Code */ void Transmit_Packet(void) { /* Create Xbee object */ XBee xbee = XBee(); /* Packet to be transmitted */ uint8_t payload[MAX_SIZE]; /* Obtain address of receiving end */ XBeeAddress64 addr64 = XBeeAddress64(0x0, 0x0); ZBTxStatusResponse txStatus = ZBTxStatusResponse(); /* Clear the payload */ memset(payload, '\0', sizeof(payload)); /* Debug Packet */ //payload[0] = '1'; //payload[1] = '5'; /* Transfer information into payload */ memcpy(payload, &G_packet, sizeof(payload)); for(int i = 0; i < MAX_SIZE; i++) { Serial.write(payload[i]);} ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload)); /* Transfer the payload */ xbee.send(zbTx); //!!Prints packet to serial monitor /* delay */ delay(1000); }
//CONSTRUCTOR //////////////////////////////////////////////////////////////////////////// XBeePlus::XBeePlus() { XBee _xbee = XBee(); ZBRxResponse rx = ZBRxResponse(); XBeeAddress64 addr64 = XBeeAddress64(0x0, 0xFFFF); ZBTxStatusResponse txStatus = ZBTxStatusResponse(); }
SrSryrsHub::SrSryrsHub() :hubSerial(Serial) ,lcd(LCD_RS, LCD_RW, LCD_Enable, LCD_D4, LCD_D5, LCD_D6, LCD_D7) ,xbee(XBee()) ,remoteAtRequest(RemoteAtCommandRequest(xba64, NULL, NULL, sizeof(NULL))) ,remoteAtResponse(RemoteAtCommandResponse()) ,ioSample(ZBRxIoSampleResponse()) ,ip(IP0, IP1, IP2, IP3) #ifdef USING_COSM ,cosmAPIKey(COSM_API_KEY) ,cosmUserAgent(COSM_USER_AGENT) ,cosmServer(COSM_IP0, COSM_IP1, COSM_IP2, COSM_IP3)//(216,52,233,122) ,cosmClient(client) ,cosmShareFeed(COSM_SHARE_FEED_ID, cosmShareDataStreams, 1) ,cosmControlFeed(COSM_CONTROL_FEED_ID, cosmControlDataStreams, 1) #endif //USING_COSM // ,server(SERVER_NUM) { /////////////////////////////////// ///// Microcontroller ///// /////////////////////////////////// internalLed = INTERNAL_LED; //////////////////////// ////// LCD ///// //////////////////////// //////////////////////// ///// XBee ///// //////////////////////// // //////////////////////////// ///// Ethernet ///// //////////////////////////// mac[0] = MAC_0; mac[1] = MAC_1; mac[2] = MAC_2; mac[3] = MAC_3; mac[4] = MAC_4; mac[5] = MAC_5; //////////////////////// ///// COSM ///// //////////////////////// #ifdef USING_COSM cosmControlVal = 0; cosmShareFeedID = COSM_SHARE_FEED_ID; cosmControlFeedID = COSM_CONTROL_FEED_ID; #endif USING_COSM }
/* Initialize objects */ void setup() { /* Variable Initialization */ count = 0; /* Create XBee Object */ XBee xbee = XBee(); /* Initialization */ init1(); //initialize sensors Serial.begin(9600); xbee.begin(Serial); //Serial.println("Main"); //debug main // initHealthSamples(); }
#include <Adafruit_NeoPixel.h> #include <avr/power.h> #include <XBee.h> #define PIN 6 #define NUMPIXELS 8 char MSG[25], CMD[30]; int DEL = 100, BRI = 20, R = 255, G = 100, B = 50, TOUT = 5; int x; long t; Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); XBee xbee = XBee(); XBeeResponse response = XBeeResponse(); ZBRxResponse rx = ZBRxResponse(); ModemStatusResponse msr = ModemStatusResponse(); void setup() { pixels.begin(); t = millis() + TOUT * 1000; CMD[0] = 'F'; //Change to Serial1 if using micro Serial.begin(9600); xbee.begin(Serial); } void checkTimeout(){ if(TOUT == 0)
namespace FireNest { struct Channel { int button_pin; int led_pin; int state; int time; }; Channel channels[] = { {2,8,0,0}, {3,9,0,0}, {4,A3,0,0}, {5,A0,0,0}, {6,A1,0,0}, {7,A2,0,0} }; //prototypes void discover(); boolean checkNDResponse(); void flashAll(int ms); void clearLeds(); void nr(uint8_t nr); uint32_t pack(uint32_t c1, uint32_t c2, uint32_t c3, uint32_t c4); //NewSoftSerial mySerial(12, 13); //used when using first button to fire all channels uint8_t channel_count = 0; uint8_t fired_channels = 0; XBee xbee = XBee(); uint8_t payload[] = { 0 }; // SH + SL Address of receiving XBee uint32_t sh = 0; uint32_t sl = 0; //XBeeAddress64 addr64; //XBeeAddress64(0x0013a200, 0x403141DA); XBeeAddress64 addr64; //XBeeAddress64(0x0013a200, 0x403141DA); ZBTxRequest zbTx; ZBTxStatusResponse txStatus = ZBTxStatusResponse(); //for device discovery uint8_t atCmd[] = {'N','D'}; AtCommandRequest atRequest = AtCommandRequest(atCmd); AtCommandResponse atResponse = AtCommandResponse(); void setupold() { //mySerial.begin(4800); //mySerial.println("Hello world"); for (int i= 0; i<CHANNELS; i++) { pinMode(channels[i].button_pin,INPUT); digitalWrite(channels[i].button_pin,HIGH); //enable internal 20K pullup pinMode(channels[i].led_pin,OUTPUT); //blink leds a bit digitalWrite(channels[i].led_pin,HIGH); delay(200); digitalWrite(channels[i].led_pin,LOW); } //debug led //pinMode(13,OUTPUT); //digitalWrite(13,HIGH); //delay(500); //digitalWrite(13,LOW); xbee.begin(XBEE_BAUD); //discover the other XBEE's address discover(); zbTx = ZBTxRequest(addr64, payload, sizeof(payload)); //send a no-op packet so that the xbees can do their magic and find each other payload[0] = 254; xbee.send(zbTx); //Flash all leds once so the user knows flashAll(500); //mySerial.println("Discovered address"); //mySerial.print("MSB: "); //mySerial.println(addr64.getMsb()); //mySerial.println(addr64.getMsb()==0x0013a200?"Yes!":"NO"); //mySerial.print("LSB: "); //mySerial.println(addr64.getLsb()); //mySerial.println(addr64.getLsb()==0x403141DA?"Yes!":"NO"); } //State 0 == not pressed, waiting for press //State 1 == pressed, debouncing time not up //Fire on press //State 2 == pressed, waiting for release //State 3 == release, debouncing time not up void loopold() { int val; int m; for (uint8_t i= 0; i<CHANNELS; i++) { m = millis(); if (channels[i].state == 0 || channels[i].state == 2) { val = digitalRead(channels[i].button_pin); if (channels[i].state == 0 && val == LOW) { //a press!, fire! uint8_t cc = i; //special case, we can fire all channels by firing the first button repeatably if (i == 0) { cc = channel_count; channel_count = (channel_count + 1) % CHANNELS; } //fire! payload[0] = cc; xbee.send(zbTx); //set as fired fired_channels |= (1 << cc); digitalWrite(channels[cc].led_pin,HIGH); //check if all is fired if (fired_channels == B00111111) { //wait a bit delay(500); //reset all channel_count = 0; fired_channels = 0; for (int j = 0; j<CHANNELS; j++) { channels[j].state = 0; digitalWrite(channels[j].led_pin,LOW); delay(300); } break; } } if ((channels[i].state == 0 && val == LOW) || (channels[i].state == 2 && val == HIGH)) { channels[i].state = (channels[i].state + 1) % 4; //change state channels[i].time = m; } } else if (m - channels[i].time > THRESHHOLD) { channels[i].state = (channels[i].state + 1) % 4; //change state } } } //discover target node void discover() { //mySerial.println("discover"); //if we don't get a address we can't fire while (true) { //send node discovery xbee.send(atRequest); //default value is that responding XBEE can wait up to six seconds before answering //so spamming it with node discoverys might be a bad thing, but waiting so long is booring so //we we'll try it and see if it works... //knight rider on the diodes let's the users know we're looking for (int i=0; i<CHANNELS; i++) { clearLeds(); digitalWrite(channels[i % CHANNELS].led_pin,HIGH); if (checkNDResponse()) { return; } } for (int i=CHANNELS-1; i>=0; i--) { clearLeds(); digitalWrite(channels[i % CHANNELS].led_pin,HIGH); if (checkNDResponse()) { return; } } } } boolean checkNDResponse() { //mySerial.println("checkNDResponse"); // wait a small bit so the animation looks good if (xbee.readPacket(ND_WAIT_TIME / 6)) { // got a response! // should be an AT command response if (xbee.getResponse().getApiId() == AT_COMMAND_RESPONSE) { xbee.getResponse().getAtCommandResponse(atResponse); if (atResponse.isOk()) { if (atResponse.getCommand()[0] == atCmd[0] && atResponse.getCommand()[1] == atCmd[1] && atResponse.getValueLength() > 3) { //mySerial.println(pack(atResponse.getValue()[2],atResponse.getValue()[3],atResponse.getValue()[4],atResponse.getValue()[5])); //mySerial.println(pack(atResponse.getValue()[6],atResponse.getValue()[7],atResponse.getValue()[8],atResponse.getValue()[9])); addr64 = XBeeAddress64( pack(atResponse.getValue()[2],atResponse.getValue()[3],atResponse.getValue()[4],atResponse.getValue()[5]),pack(atResponse.getValue()[6],atResponse.getValue()[7],atResponse.getValue()[8],atResponse.getValue()[9]) ); return true; } } else { //nss.print("Command return error code: "); //nss.println(atResponse.getStatus(), HEX); nr(1); } } else { //nss.print("Expected AT response but got "); //nss.print(xbee.getResponse().getApiId(), HEX); nr(2); } } else { // at command failed if (xbee.getResponse().isError()) { //nss.print("Error reading packet. Error code: "); //nss.println(xbee.getResponse().getErrorCode()); nr(3); } else { //nss.print("No response from radio"); nr(4); } } return false; } //flash leds once, variable time void flashAll(int ms) { for (int i=0;i<CHANNELS; i++) { digitalWrite(channels[i].led_pin,HIGH); } delay(ms); clearLeds(); } //clear all leds void clearLeds() { for (int i=0;i<CHANNELS; i++) { digitalWrite(channels[i].led_pin,LOW); } } //light up a nr, binary code void nr(uint8_t nr) { //TODO: smarter code... if (nr & B00000001) { digitalWrite(8,HIGH); } if (nr & B00000010) { digitalWrite(9,HIGH); } if (nr & B00000100) { digitalWrite(A3,HIGH); } if (nr & B00001000) { digitalWrite(A0,HIGH); } if (nr & B00010000) { digitalWrite(A1,HIGH); } if (nr & B00100000) { digitalWrite(A2,HIGH); } } uint32_t pack(uint32_t c1, uint32_t c2, uint32_t c3, uint32_t c4) { return (c1 << 24) | (c2 << 16) | (c3 << 8) | (c4); } }
XbeeApiStream::XbeeApiStream() { xbee = XBee(); coordAddr64 = XBeeAddress64(0x00000000, 0x0000ffff); }
#include "XBeeMenu.h" // /*#define Serial SERIAL_PORT_USBVIRTUAL */ XBee xbee = XBee(); //создаем XBee библиотеку // ++++++++++ настройки для приема и передачи пакета +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ uint8_t payload[64] = { 0 }; uint8_t shCmd[] = { 'S','H' }; // serial high Старший байт адреса куда отправляется пакет uint8_t slCmd[] = { 'S','L' }; // serial low Младший байт адреса куда отправляется пакет uint8_t assocCmd[] = { 'A','I' }; // association status Индикация присоединения //Считывает информацию о последнем запросе узла на присоединение: //0x00 – Завершено успешно - Координатор стартовал илиМаршрутизатор/Конечное устройство //обнаружило и присоединилось родительскому устройству. //0x21 – Сканирование не обнаружило сети //0x22 – Сканирование не обнаружило работающей сети с текущими установками SC и ID //0x23 – Работающий Координатор или Маршрутизаторы найдены, но они не дали разрешение на //присоединение к сети (истекло время NJ) //0x27 – Попытка присоединения не удалась //0x2A – Запуск Координатора не удался //0xFF – Идет поиск родительского устройства uint8_t irCmd[] = { 'I','R' }; // uint8_t opCmd[] = { 'O','P' }; // Номер сети (PAN ID) uint8_t IDCmd[] = { 'I','D' }; // Номер сети (ID) uint8_t OICmd[] = { 'O','I' }; // Operating 16-bit PAN ID(OI) uint8_t MYCmd[] = { 'M','Y' }; // Номер сети (16-bit Network Adress