Skip to content

Commit 52f751f

Browse files
committed
Saturday morning
1 parent bf2dab4 commit 52f751f

File tree

339 files changed

+54952
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

339 files changed

+54952
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#include <JeeLib.h>
2+
#include <NanodeUNIO.h>
3+
#include <NanodeUIP.h>
4+
#include <NanodeMQTT.h>
5+
6+
NanodeMQTT mqtt(&uip);
7+
struct timer my_timer;
8+
9+
#define STRING_BUFFER 128
10+
11+
// RF stuff
12+
#define RF_NODEID 1 // master node
13+
#define RF_CHANNEL 125
14+
15+
#define GREEN_LED 5
16+
#define RED_LED 6
17+
18+
19+
// this must be added since we're using the watchdog for low-power waiting
20+
// ISR(WDT_vect) { Sleepy::watchdogEvent(); }
21+
22+
unsigned int count_crc = 0;
23+
unsigned int count_pkts = 0;
24+
25+
// Payload data structure
26+
typedef struct {
27+
int nodeid; // sending node ID
28+
char type;
29+
float data;
30+
} Payload;
31+
Payload data;
32+
33+
34+
35+
void setup() {
36+
byte macaddr[6];
37+
NanodeUNIO unio(NANODE_MAC_DEVICE);
38+
39+
pinMode(GREEN_LED, OUTPUT);
40+
digitalWrite(GREEN_LED, HIGH); //off
41+
42+
Serial.begin(57600);
43+
Serial.println("Initialising...");
44+
45+
unio.read(macaddr, NANODE_MAC_ADDRESS, 6);
46+
uip.init(macaddr);
47+
48+
// FIXME: use DHCP instead
49+
uip.set_ip_addr(192, 168, 1, 199);
50+
uip.set_netmask(255, 255, 255, 0);
51+
52+
uip.wait_for_link();
53+
Serial.println("Link is up");
54+
55+
// FIXME: resolve using DNS instead
56+
mqtt.set_server_addr(192, 168, 1, 103);
57+
mqtt.connect();
58+
59+
rf12_initialize(RF_NODEID, RF12_868MHZ, RF_CHANNEL);
60+
61+
// flash the LED to signify booting
62+
digitalWrite(GREEN_LED, LOW);
63+
delay(100);
64+
digitalWrite(GREEN_LED, HIGH);
65+
delay(150);
66+
digitalWrite(GREEN_LED, LOW);
67+
delay(200);
68+
digitalWrite(GREEN_LED, HIGH);
69+
}
70+
71+
72+
void loop() {
73+
char topic[STRING_BUFFER];
74+
char message[STRING_BUFFER];
75+
76+
uip.poll();
77+
78+
if (rf12_recvDone()) {
79+
if (rf12_crc == 0) {
80+
count_pkts++;
81+
82+
Payload temp = *(Payload*) rf12_data;
83+
data = temp;
84+
85+
Serial.print("n:");
86+
Serial.print(data.nodeid);
87+
Serial.print("\tt:");
88+
Serial.print(data.type);
89+
Serial.print("\td:");
90+
Serial.print(data.data);
91+
Serial.println();
92+
93+
sprintf (topic, "nanode/sensor/%d", data.nodeid);
94+
dtostrf(data.data, 4, 2, message);
95+
96+
// quick flash on receipt of packet
97+
digitalWrite(GREEN_LED, LOW);
98+
delay(50);
99+
digitalWrite(GREEN_LED, HIGH);
100+
101+
Serial.print(topic);
102+
Serial.print(", ");
103+
Serial.println(message);
104+
105+
106+
107+
108+
if (mqtt.connected()) {
109+
Serial.print("Publishing ");
110+
Serial.print(topic);
111+
Serial.print(":");
112+
Serial.println(message);
113+
114+
mqtt.publish(topic, message);
115+
mqtt.publish("Test", "Hello World!");
116+
Serial.println("Published.");
117+
118+
// quick flash on publish
119+
digitalWrite(RED_LED, LOW);
120+
delay(50);
121+
digitalWrite(RED_LED, HIGH);
122+
}
123+
} else {
124+
count_crc++;
125+
}
126+
}
127+
}
128+

libraries/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)