opportunistic-xbee/well/main/main.ino

58 lines
1.2 KiB
C++

#include <Wire.h>
#include <XBee.h>
#include "protocol.h"
#include <LiquidCrystal_I2C.h>
// Peripherals
LiquidCrystal_I2C screen(0x27, 16, 2);
XBee xbee = XBee();
// ACTUAL DATA
uint8_t wave_id = 250;
struct discover dsc = {0,0,0};
void setup() {
Serial.begin(38400);
Serial.println("+ ready");
screen.begin();
screen.backlight();
xbee.setSerial(Serial1);
Serial1.begin(38400);
// xbee.begin(38400);
}
void loop() {
delay(WAVE_TIMEOUT);
// increment wave id (will overflow from 255 to 0)
dsc.wave = ++wave_id; // set wave id
screen.clear();
screen.print("+ wave");
screen.print(dsc.wave);
uint8_t payload[3] = {dsc.opcode, dsc.wave, dsc.dist};
XBeeAddress64 addr64 = XBeeAddress64(0x00000000, 0x0000FFFF);
Tx64Request tx = Tx64Request(addr64, payload, sizeof(payload));
xbee.send(tx);
/* Check the status of our sent payload (not mandatory)
TxStatusResponse txStatus = TxStatusResponse();
xbee.readPacket();
if( xbee.getResponse().isAvailable() ){
if( xbee.getResponse().getApiId() == TX_STATUS_RESPONSE ){
xbee.getResponse().getTxStatusResponse(txStatus);
txStatus.isSuccess() && Serial.println(" ... sent") || Serial.println(" ... failed");
}
}
*/
}