opportunistic-xbee/well/main/main.ino

59 lines
1.3 KiB
Arduino
Raw Normal View History

2018-12-01 17:26:27 +00:00
#include <Wire.h>
#include <XBee.h>
#include "protocol.h"
#include <LiquidCrystal_I2C.h>
2018-12-01 17:38:00 +00:00
#define WAVE_TIMEOUT 5000
2018-12-01 17:26:27 +00:00
// Peripherals
LiquidCrystal_I2C screen(0x27, 16, 2);
XBee xbee = XBee();
// ACTUAL DATA
uint8_t wave_id = 250;
struct discover dsc = {0,0,0};
2018-12-01 17:26:27 +00:00
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
2018-12-01 17:26:27 +00:00
screen.clear();
screen.print("+ wave");
screen.print(dsc.wave);
2018-12-01 17:26:27 +00:00
uint8_t payload[3] = {dsc.opcode, dsc.wave, dsc.dist};
2018-12-01 17:26:27 +00:00
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");
}
}
*/
}