-
Notifications
You must be signed in to change notification settings - Fork 0
/
PiSerialGateway.ino
73 lines (61 loc) · 1.94 KB
/
PiSerialGateway.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <RFM69.h> //get it here: http://github.com/lowpowerlab/rfm69
#include <SPIFlash.h> //get it here: http://github.com/lowpowerlab/spiflash
#include <SPI.h> //comes with Arduino IDE (www.arduino.cc)
#define NODEID 1 // gateway has ID 1
#define NETWORKID 200
#define FREQUENCY RF69_915MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_868MHZ)
#define ENCRYPTKEY "sampleEncryptKey" //has to be same 16 characters/bytes on all nodes, not more not less!
#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define LED 9
#define FLASH_CS 8
#define SERIAL_BAUD 115200
#define SERIAL_EN //comment out if you don't want any serial verbose output
#define ACK_TIME 30 // # of ms to wait for an ack
//*****************************************************************************************************************************
RFM69 radio;
SPIFlash flash(FLASH_CS, 0xEF30); //EF40 for 16mbit windbond chip
char data[100];
char _rssi[5];
void setup()
{
pinMode(10, OUTPUT);
Serial.begin(115200);
radio.initialize(FREQUENCY,NODEID,NETWORKID);
#ifdef IS_RFM69HW
radio.setHighPower(); //uncomment only for RFM69HW!
#endif
radio.encrypt(ENCRYPTKEY);
flash.initialize();
}
void loop()
{
if (radio.receiveDone())
{
int rssi = radio.RSSI;
if (radio.DATALEN > 0)
{
for (byte i = 0; i < radio.DATALEN; i++)
data[i] = (char)radio.DATA[i];
}
dtostrf(rssi, 3, 0, _rssi);
strcat(data, ",r:");
strcat(data, _rssi);
if (radio.ACKRequested())
{
byte theNodeID = radio.SENDERID;
radio.sendACK();
}
Serial.println(data);
delay(1);
memset(data, 0, sizeof data);
memset(_rssi, 0, sizeof _rssi);
Blink(LED,10);
}
}
void Blink(byte PIN, int DELAY_MS)
{
pinMode(PIN, OUTPUT);
digitalWrite(PIN,HIGH);
delay(DELAY_MS);
digitalWrite(PIN,LOW);
}