Skip to content

Commit f994b5f

Browse files
author
Steve Trease
committed
New nanode based message receiver and MQTT publisher - that actually seems to work
1 parent f4a8e15 commit f994b5f

File tree

341 files changed

+31137
-8967
lines changed

Some content is hidden

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

341 files changed

+31137
-8967
lines changed

.DS_Store

-3 KB
Binary file not shown.

Jeenode/.DS_Store

-12 KB
Binary file not shown.

Jeenode_3/.DS_Store

-6 KB
Binary file not shown.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#include <JeeLib.h>
2+
#include <NanodeUNIO.h>
3+
#include <NanodeUIP.h>
4+
#include <NanodeMQTT.h>
5+
6+
NanodeMQTT mqtt(&uip);
7+
8+
#define STRING_BUFFER 64
9+
10+
// RF stuff
11+
#define RF_NODEID 1 // master node
12+
#define RF_CHANNEL 125
13+
14+
#define GREEN_LED 5
15+
#define RED_LED 6
16+
17+
#define ON LOW
18+
#define OFF HIGH
19+
20+
21+
// this must be added since we're using the watchdog for low-power waiting
22+
// ISR(WDT_vect) { Sleepy::watchdogEvent(); }
23+
24+
25+
char topic[STRING_BUFFER];
26+
char message[STRING_BUFFER];
27+
28+
// Payload data structure
29+
typedef struct {
30+
int nodeid; // sending node ID
31+
char type;
32+
float data;
33+
} Payload;
34+
Payload data;
35+
36+
37+
38+
void setup() {
39+
byte macaddr[6];
40+
NanodeUNIO unio(NANODE_MAC_DEVICE);
41+
42+
pinMode(RED_LED, OUTPUT);
43+
pinMode(GREEN_LED, OUTPUT);
44+
digitalWrite(RED_LED, ON);
45+
digitalWrite(GREEN_LED, ON);
46+
47+
Serial.begin(57600);
48+
Serial.println("Initialising...");
49+
50+
unio.read(macaddr, NANODE_MAC_ADDRESS, 6);
51+
uip.init(macaddr);
52+
53+
// FIXME: use DHCP instead
54+
uip.set_ip_addr(192, 168, 1, 198 );
55+
uip.set_netmask(255, 255, 255, 0);
56+
57+
digitalWrite(RED_LED, OFF);
58+
59+
uip.wait_for_link();
60+
Serial.println("Link is up");
61+
62+
digitalWrite(RED_LED, ON);
63+
64+
// FIXME: resolve using DNS instead
65+
mqtt.set_server_addr(192, 168, 1, 103);
66+
mqtt.connect();
67+
rf12_initialize(RF_NODEID, RF12_868MHZ, RF_CHANNEL);
68+
mqtt.publish("test", "nanode booted");
69+
digitalWrite(GREEN_LED, OFF);
70+
digitalWrite(RED_LED, OFF);
71+
}
72+
73+
74+
void loop() {
75+
76+
uip.poll();
77+
// Serial.print(".");
78+
79+
if (rf12_recvDone()) {
80+
if (rf12_crc == 0) {
81+
Payload temp = *(Payload*) rf12_data;
82+
data = temp;
83+
84+
Serial.print("n:");
85+
Serial.print(data.nodeid);
86+
Serial.print("\tt:");
87+
Serial.print(data.type);
88+
Serial.print("\td:");
89+
Serial.print(data.data);
90+
Serial.println();
91+
92+
sprintf (topic, "nanode/sensor/%d/%c", data.nodeid, data.type);
93+
dtostrf(data.data, 10, 8, message);
94+
95+
if (mqtt.connected()) {
96+
digitalWrite(GREEN_LED, ON);
97+
digitalWrite(RED_LED, OFF);
98+
99+
Serial.print("Publishing ");
100+
Serial.print(topic);
101+
Serial.print(" : ");
102+
Serial.println(message);
103+
104+
mqtt.publish(topic, message);
105+
106+
digitalWrite(GREEN_LED, OFF);
107+
} else {
108+
digitalWrite(RED_LED, ON);
109+
Serial.println("not connected");
110+
}
111+
}
112+
}
113+
}
114+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
int led = 13;
2+
3+
// the setup routine runs once when you press reset:
4+
void setup() {
5+
// initialize the digital pin as an output.
6+
pinMode(led, OUTPUT);
7+
}
8+
9+
// the loop routine runs over and over again forever:
10+
void loop() {
11+
int channel = 1;
12+
13+
for (int note = 1; note < 255; note++) {
14+
usbMIDI.sendNoteOn(note, 99, channel);
15+
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
16+
delay (100);
17+
18+
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
19+
usbMIDI.sendNoteOff(note, 0, channel);
20+
delay (100);
21+
}
22+
for (int note = 255; note > 0; note--) {
23+
usbMIDI.sendNoteOn(note, 99, channel);
24+
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
25+
delay (100);
26+
27+
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
28+
usbMIDI.sendNoteOff(note, 0, channel);
29+
delay (100);
30+
}
31+
}
32+
33+
34+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
#include <Encoder.h>
3+
4+
int led = 13;
5+
int channel = 1;
6+
int note = 0; // C4
7+
int octave = 5;
8+
9+
long positionOne = 0;
10+
long positionTwo = 0;
11+
12+
Encoder knobOne(0, 1);
13+
Encoder knobTwo(2, 3);
14+
15+
16+
void setup () {
17+
pinMode(led, OUTPUT);
18+
digitalWrite(led, LOW);
19+
20+
}
21+
22+
23+
void loop () {
24+
long newOne, newTwo;
25+
int changed = 0;
26+
27+
newOne = knobOne.read();
28+
newTwo = knobTwo.read();
29+
30+
31+
if (newOne != positionOne) {
32+
if (newOne < positionOne) {
33+
note--;
34+
} else {
35+
note++;
36+
}
37+
note = constrain(note,0, 11);
38+
positionOne = newOne;
39+
changed = 1;
40+
}
41+
if (newTwo != positionTwo) {
42+
if (newTwo < positionTwo) {
43+
octave--;
44+
} else {
45+
octave++;
46+
}
47+
octave = constrain (octave, 0, 10);
48+
positionTwo = newTwo;
49+
changed = 1;
50+
}
51+
52+
if (changed == 1) {
53+
int midiNote = (octave * 12) + note;
54+
digitalWrite(led, HIGH);
55+
usbMIDI.sendNoteOn(midiNote, 99, channel);
56+
delay(10);
57+
usbMIDI.sendNoteOn(midiNote, 0, channel);
58+
digitalWrite(led, LOW);
59+
changed = 0;
60+
}
61+
}
62+
63+
64+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <Encoder.h>
2+
3+
int led = 13;
4+
int channel = 1;
5+
int note = 0; // C4
6+
int octave = 5;
7+
8+
long positionOne = 0;
9+
long positionTwo = 0;
10+
11+
Encoder knobOne(0, 1);
12+
Encoder knobTwo(2, 3);
13+
14+
15+
void setup () {
16+
pinMode(led, OUTPUT);
17+
digitalWrite(led, LOW);
18+
19+
}
20+
21+
22+
void loop () {
23+
long newOne, newTwo;
24+
int changed = 0;
25+
26+
newOne = knobOne.read();
27+
newTwo = knobTwo.read();
28+
29+
30+
if (newOne != positionOne) {
31+
if (newOne < positionOne) {
32+
note--;
33+
} else {
34+
note++;
35+
}
36+
note = constrain(note,0, 11);
37+
positionOne = newOne;
38+
changed = 1;
39+
}
40+
if (newTwo != positionTwo) {
41+
if (newTwo < positionTwo) {
42+
octave--;
43+
} else {
44+
octave++;
45+
}
46+
octave = constrain (octave, 0, 10);
47+
positionTwo = newTwo;
48+
changed = 1;
49+
}
50+
51+
if (changed == 1) {
52+
int midiNote = (octave * 12) + note;
53+
digitalWrite(led, HIGH);
54+
usbMIDI.sendNoteOn(midiNote, 99, channel);
55+
delay(10);
56+
usbMIDI.sendNoteOn(midiNote, 0, channel);
57+
digitalWrite(led, LOW);
58+
changed = 0;
59+
}
60+
}
61+
62+
63+

RadioBlips/.DS_Store

-6 KB
Binary file not shown.

Webserver temp sensor/.DS_Store

-6 KB
Binary file not shown.

hardware/.DS_Store

-6 KB
Binary file not shown.

0 commit comments

Comments
 (0)