Skip to content

Commit

Permalink
working on lamp node
Browse files Browse the repository at this point in the history
  • Loading branch information
marco committed Oct 9, 2016
1 parent 6191388 commit 14ce69f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
29 changes: 21 additions & 8 deletions arduino_code/onos_lamp_node_WLightSA/onos_lamp_node_WLightSA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
#define RFM69_CS 10
#define RFM69_IRQ 2
#define RFM69_IRQN 0 // Pin 2 is IRQ 0!
#define RFM69_RST 3
#define RFM69_RST 9

#define LED 5 // onboard blinky

Expand Down Expand Up @@ -113,7 +113,7 @@ unsigned long get_address_timeout=0;


/*
WLightSS node parameter:
WLightSA node parameter:
relay_pin --> the pin where the relay coil is connected
relay_check_pin-->the pin connected to the relay that tell the node if the relay is on or off
photoresistor_pin
Expand Down Expand Up @@ -144,7 +144,7 @@ int received_message_value;
char received_message_answer[rx_msg_lenght+6]="er00_#]";
int received_message_address=0; //must be int..
char filtered_onos_message[rx_msg_lenght+3];
char syncMessage[28];
char syncMessage[48];
char str_this_node_address[4];
//////////////////////////////////End of Standard part to run decodeOnosCmd()//////////////////////////////////

Expand Down Expand Up @@ -193,12 +193,13 @@ int freeRam ()
void composeSyncMessage(){


//[S_001um3.05ProminiS0001000_#]
//[S_001ul3.05ProminiS0001000_#]
// example: [S_001um3.05ProminiS00010167123_#] #lux=167 lamp is at 0 , 123 minutes on since boot
if (lamp_state==1){

if (time_continuos_on!=0){
time_from_turn_on=time_from_turn_on+(millis()-time_continuos_on);
time_continuos_on=millis();
}

}
Expand Down Expand Up @@ -252,7 +253,8 @@ void composeSyncMessage(){
strcpy(syncMessage, "");
strcpy(syncMessage, "[S_");
strcat(syncMessage, str_this_node_address);
strcat(syncMessage, "um");
strcat(syncMessage, "ul");
// strcat(syncMessage, "sy");
strcat(syncMessage, node_fw);
strcat(syncMessage, serial_number);
strcat(syncMessage, char_lamp_state);
Expand Down Expand Up @@ -462,7 +464,7 @@ void decodeOnosCmd(const char *received_message){
time_continuos_on=millis();
while (digitalRead(received_message_second_pin_used)!=received_message_value){
delay(1);
if (millis()-time_from_turn_on>100){ // if the relay hasn't swiched after 100 ms from command..is broken..
if (millis()-time_continuos_on>100){ // if the relay hasn't swiched after 100 ms from command..is broken..
strcpy(received_message_answer,"err2_relay_#]");
return;
}
Expand All @@ -476,6 +478,7 @@ void decodeOnosCmd(const char *received_message){

if (time_continuos_on!=0){
time_from_turn_on=time_from_turn_on+(millis()-time_continuos_on);
time_continuos_on=millis();
}

if (received_message_value==1){
Expand Down Expand Up @@ -578,7 +581,14 @@ void decodeOnosCmd(const char *received_message){


void setup() {
noInterrupts(); // Disable interrupts //important for lamp node

pinMode(relay_pin, OUTPUT);
pinMode(RFM69_RST, OUTPUT); //important for lamp node

digitalWrite(RFM69_RST, HIGH); //important for lamp node

// digitalWrite(RFM69_RST,0); //radio reset pin
lamp_state=EEPROM.read(lamp_state_address);
digitalWrite(relay_pin,!lamp_state); //set relay

Expand Down Expand Up @@ -620,12 +630,15 @@ void setup() {
Serial.println(lamp_state);

// Hard Reset the RFM module
pinMode(RFM69_RST, OUTPUT);

digitalWrite(RFM69_RST, HIGH);
delay(100);
digitalWrite(RFM69_RST, LOW);
delay(100);


interrupts(); // Enable interrupts

// Initialize radio
radio.initialize(FREQUENCY,this_node_address,NETWORKID);
if (IS_RFM69HCW) {
Expand Down Expand Up @@ -774,7 +787,7 @@ void loop() {

}

else if ((millis()-sync_time)>500){ //every 5000 ms
else if ((millis()-sync_time)>5000){ //every 5000 ms


sync_time=millis();
Expand Down
9 changes: 9 additions & 0 deletions scp
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ scp -r $(ls | grep -v -e docs -e arduino_code -e online_db -e tests ) root@192

scp -r $(ls | grep -v -e docs -e arduino_code -e online_db -e tests ) root@192.168.1.2:/bin/onos/



git add *
git commit -a -m "working on lamp node"
git push -u origin master

git add * & git commit -m "Initial commit marco" & git push -u origin master


2 changes: 1 addition & 1 deletion scripts_folder/arduinoserial.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def read_data(self): # thread function
cmd=buf[cmd_start:cmd_end+3]


if( (cmd[6]=="s")&(cmd[7]=="y") ): # [S_001sy3.05ProminiS0001_#]
if( (cmd[6]=="s")&(cmd[7]=="y") )or((cmd[6]=="u")&(cmd[7]=="l")) : # [S_001sy3.05ProminiS0001_#]
print "serial rx cmd="+cmd
buf=""
try:
Expand Down
4 changes: 2 additions & 2 deletions tests/problems_and_solutions
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ I will use post instead that get message
If the node that have to send a sync message is a lamp node or a plug node it will write:
3 bytes with "[S_" for the start of the message
3 bytes for the address of the node ("001" for the arduino gateway)
2 bytes containing "um" for the type of msg (um stand for update message)
2 bytes containing "ul" for the type of msg (um stand for update lamp)
4 byte with the fw version for example "5.23"
12 byte to tell the node serial number
1 byte to tell the status of the node ( relay on or off )
3 byte to tell the sensor value on A0 (lux for "lamp type" and maybe ampere for "plug type")
3 bytes to tell how many minutes the relay have been stayed on since the node was powered on (will restart after 10 hours).
3 bytes with "_#]" to close the message
example: [S_001um3.05ProminiS00010167123_#] #lux=167 lamp is at 0 , 123 minutes on since boot
example: [S_001ul3.05ProminiS00010167123_#] #lux=167 lamp is at 0 , 123 minutes on since boot

////////////////////////////////////OLD... TO UPDATE/////////////////////////////////////////////////////////

Expand Down

0 comments on commit 14ce69f

Please sign in to comment.