Last active
November 9, 2017 12:57
-
-
Save Servuc/cd3605c9591cc83a3442f3cff2bec3f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Licence MIT | |
@Servuc | |
Linked to my teaching http://servuc.github.io/teaching/iot-4.html | |
Base code to help students :P | |
*/ | |
// Enable and select radio type attached | |
#define MY_DEBUG | |
#define MY_RADIO_NRF24 | |
#define MY_NODE_ID 10 //TODO : SET YOUR ID ! | |
#define PIN_ID 8 //For the LED | |
#include <SPI.h> | |
#include <MySensors.h> | |
#define CHILD_ID 1 | |
//Message to one other node, you should add missing message to adjacent nodes | |
MyMessage msg(CHILD_ID, V_POSITION); | |
//Message to indicate to master that sensor light is ON | |
MyMessage msgToMaster(CHILD_ID, V_LIGHT_LEVEL); | |
void setup() | |
{ | |
Serial.println("Setup : Begin"); | |
pinMode(PIN_ID, OUTPUT); | |
digitalWrite(PIN_ID, LOW); | |
digitalWrite(PIN_ID, HIGH); | |
delay(500); | |
digitalWrite(PIN_ID, LOW); | |
Serial.println("Setup : End"); | |
} | |
void presentation() { | |
digitalWrite(PIN_ID, HIGH); | |
delay(500); | |
digitalWrite(PIN_ID, LOW); | |
} | |
void receive(const MyMessage &message) { | |
Serial.print("From : "); | |
Serial.println(message.sender); | |
if( message.type == V_LIGHT_LEVEL && message.sender == 0 ) { //Gateway and light order | |
//TODO : Shutdown light, digitalWrite | |
return; | |
} | |
if( message.type == V_POSITION ) { | |
//TODO : Set on light, digitalWrite | |
//Send variable 1 to master : Mean light is ON | |
send( msgToMaster.set(1) ); | |
//Display next node message | |
char * myNextNode = message.getString(); | |
Serial.print("End node in path : "); | |
Serial.println(myNextNode); | |
//Message here contains information about next node, contact them | |
//TODO : Write other conditions for other nodes. | |
//Here we are on node 10, just next to 11, so if 11 is the end, set a message to node 11 with end node 11 | |
//Here we are on node 10, just next to 12, so if 12 is the end, perhaps send a message to 11 | |
/** | |
For example : | |
switch( END ) { | |
case XXX : | |
UPDATE msg DESTINATION (not msgToMaster !!!) | |
send( UPDATE msg WITH end DESTINATION ); | |
break; | |
case YYY : | |
UPDATE msg DESTINATION (not msgToMaster !!!) | |
send( UPDATE msg WITH end DESTINATION ); | |
break; | |
}*/ | |
} | |
} | |
void loop() | |
{ | |
delay(5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment