Skip to content

Commit

Permalink
continued to work on serial interface0
Browse files Browse the repository at this point in the history
  • Loading branch information
marco committed Aug 21, 2016
1 parent 9331db1 commit a5d0bc0
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 23 deletions.
12 changes: 6 additions & 6 deletions arduino_code/onos_node_Plug6way.pde
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ uint16_t analog_values[17];// store the values from analog input 2 bytes for
char node_type='a'; //banana temp 'a' for arduino pro mini
char serial_char=1 ; //banana to read from eprom
char node_fw[]="5.13";
char node_code_name[]="Plug6way0002";
char serial_number[]="0002"; //BANANA TO READ FROM EEPROM
char node_code_name[]="Plug6way0001";
char serial_number[]="0001"; //BANANA TO READ FROM EEPROM



Expand Down Expand Up @@ -347,7 +347,7 @@ void server_handler(EthernetClient client_query ){

counter=0;
char data_from_serial [25];
char second_array[21];
char filtered_onos_message[21];
unsigned long timeout=millis()+200;


Expand Down Expand Up @@ -404,16 +404,16 @@ void server_handler(EthernetClient client_query ){


for (uint8_t pointer = 0; pointer <= serial_msg_lenght; pointer++) {
second_array[pointer]=data_from_serial[counter-serial_msg_lenght+pointer];
filtered_onos_message[pointer]=data_from_serial[counter-serial_msg_lenght+pointer];

#if defined(DEVMODE)
Serial.println(second_array[pointer]);
Serial.println(filtered_onos_message[pointer]);

#endif

}

decodeOnosCmd(second_array);
decodeOnosCmd(filtered_onos_message);

if(((serial_message_answer[0]=='o')&&(serial_message_answer[1]=='k'))||(strcmp(serial_message_answer,"remote_#]")==0)){
char onos_cmd_type= serial_message_type_of_onos_cmd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#include <RH_RF69.h>
#include <SPI.h>

#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2
#define CLIENT_ADDRESS 2
#define SERVER_ADDRESS 1

//#define DEVMODE 0

Expand Down Expand Up @@ -158,14 +158,14 @@ void decodeOnosCmd(const char *received_message){

switch (serial_message_type_of_onos_cmd) {

case 'd':{ //digital write onos_d07v001s0000_#]
case 'd':{ //digital write onos_d05v001s0001_#]
pinMode(serial_message_first_pin_used, OUTPUT);
digitalWrite(serial_message_first_pin_used, serial_message_value);
strcpy(serial_message_answer,"ok_#]");
break;
}

case 'a':{ //pwm write onos_a07v100s0000_#]
case 'a':{ //pwm write onos_a07v100s0001_#]
analogWrite(serial_message_first_pin_used, serial_message_value);
strcpy(serial_message_answer,"ok_#]");
break;
Expand All @@ -177,9 +177,12 @@ void decodeOnosCmd(const char *received_message){
break;
}

case 'g':{ //get digital status onos_g0708v0s0001_#]
case 'g':{ //get digital status onos_g0403v0s0001_#]
pinMode(serial_message_first_pin_used, INPUT);
pinMode(serial_message_second_pin_used, INPUT);
pinMode(serial_message_second_pin_used, INPUT);
digitalWrite(serial_message_first_pin_used,1); //enable internal pullup resistors
digitalWrite(serial_message_second_pin_used,1);//enable internal pullup resistors
delayMicroseconds(20); //wait a bit
char val_first_pin=digitalRead(serial_message_first_pin_used)+48;
char val_second_pin=digitalRead(serial_message_second_pin_used)+48;
strcpy(serial_message_answer,"");
Expand Down Expand Up @@ -279,10 +282,19 @@ void setup()
if (!manager.init()){
Serial.println("init failed");
radio_enabled=0;

uint8_t key[] = { 0x05, 0x02, 0x03, 0x07, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x05, 0x05, 0x06, 0x07, 0x08};
driver.setEncryptionKey(key);



}

Serial.println(F("ready"));



// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM

// If you are using a high power RF69, you *must* set a Tx power in the
Expand Down Expand Up @@ -327,7 +339,7 @@ void loop()

counter=0;
char data_from_serial [25];
char second_array[21];
char filtered_onos_message[21];
unsigned long timeout=millis()+200;

while (Serial.available() > 0) {
Expand Down Expand Up @@ -373,14 +385,17 @@ void loop()
Serial.println(F("onos cmd received0:"));
#endif

uint8_t message_copy[21];

for (uint8_t pointer = 0; pointer <= serial_msg_lenght; pointer++) {
second_array[pointer]=data_from_serial[counter-serial_msg_lenght+pointer];
filtered_onos_message[pointer]=data_from_serial[counter-serial_msg_lenght+pointer];
message_copy[pointer]=data_from_serial[counter-serial_msg_lenght+pointer];

//Serial.println("mmm");
//Serial.println(second_array[pointer]);
//Serial.println(filtered_onos_message[pointer]);
}

decodeOnosCmd(second_array);
decodeOnosCmd(filtered_onos_message);

if(((serial_message_answer[0]=='o')&&(serial_message_answer[1]=='k'))||(strcmp(serial_message_answer,"remote_#]")==0)){
char onos_cmd_type= serial_message_type_of_onos_cmd;
Expand All @@ -394,8 +409,10 @@ void loop()
Serial.println(serial_message_sn);
Serial.println("__sn");
*/
if (serial_message_sn==serial_number) {//onos command for this arduino node
Serial.print("ok_local");

if (strcmp(serial_message_sn,serial_number)==0) {//onos command for this arduino node
//Serial.print("ok_local");
strcpy(serial_message_answer,"ok_local_#]");
counter=0;
}
else{ //onos command to send to a remote node
Expand All @@ -404,6 +421,33 @@ void loop()

//put here the radio transmit part


uint8_t remote_node_address=(serial_message_sn[0]-48)*1000+(serial_message_sn[1]-48)*100+(serial_message_sn[2]-48)*10+(serial_message_sn[3]-48)*1;
// Send a message to manager_server
if (manager.sendtoWait(message_copy, sizeof(message_copy),remote_node_address)) {
// Now wait for a reply from the server
uint8_t len = sizeof(buf);
uint8_t from;
if (manager.recvfromAckTimeout(buf, &len, 2000, &from)){
//Serial.print("got reply from : 0x");
//Serial.print(from, HEX);
//Serial.print(": ");
//Serial.println((char*)buf);
strcpy(serial_message_answer,(char*)buf);
}
else{
// Serial.println("No reply, is rf69_reliable_datagram_server running?");
strcpy(serial_message_answer,"ertx0_#]");
}
}
else{
// Serial.println("sendtoWait failed");
strcpy(serial_message_answer,"ertx1_#]");
//delay(500);
}



}
else {//radio is disabled or not working
strcpy(serial_message_answer,"radio_er0_#]");
Expand Down
65 changes: 65 additions & 0 deletions arduino_code/rf69_reliable_datagram_server.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// rf69_reliable_datagram_server.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple addressed, reliable messaging server
// with the RHReliableDatagram class, using the RH_RF69 driver to control a RF69 radio.
// It is designed to work with the other example rf69_reliable_datagram_client
// Tested on Moteino with RFM69 http://lowpowerlab.com/moteino/
// Tested on miniWireless with RFM69 www.anarduino.com/miniwireless
// Tested on Teensy 3.1 with RF69 on PJRC breakout board

#include <RHReliableDatagram.h>
#include <RH_RF69.h>
#include <SPI.h>

#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2

// Singleton instance of the radio driver
RH_RF69 driver;
//RH_RF69 driver(15, 16); // For RF69 on PJRC breakout board with Teensy 3.1
//RH_RF69 rf69(4, 2); // For MoteinoMEGA https://lowpowerlab.com/shop/moteinomega

// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram manager(driver, SERVER_ADDRESS);

void setup()
{
Serial.begin(9600);
if (!manager.init())
Serial.println("init failed");

uint8_t key[] = { 0x05, 0x02, 0x03, 0x07, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x05, 0x05, 0x06, 0x07, 0x08};
driver.setEncryptionKey(key);
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM

// If you are using a high power RF69, you *must* set a Tx power in the
// range 14 to 20 like this:
// driver.setTxPower(14);
}

uint8_t data[] = "And hello back to you";
// Dont put this on the stack:
uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];

void loop()
{
if (manager.available())
{
// Wait for a message addressed to us from the client
uint8_t len = sizeof(buf);
uint8_t from;
if (manager.recvfromAck(buf, &len, &from))
{
Serial.print("got request from : 0x");
Serial.print(from, HEX);
Serial.print(": ");
Serial.println((char*)buf);

// Send a reply back to the originator client
if (!manager.sendtoWait(data, sizeof(data), from))
Serial.println("sendtoWait failed");
}
}
}

3 changes: 3 additions & 0 deletions bug
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ main webserver



se si si accende onoscenter senza internet l'ora resta sbagliata anche quando poi si collega internet ..falso?


main error in handle_new_query_to_remote_node_thread:('string indices must be integers',)


Expand Down
2 changes: 1 addition & 1 deletion scripts_folder/globalVar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@
hardwareModelDict["ProminiA"]["pin_mode"]["servo_output"]={"servo":[(5)]}
#hardwareModelDict["ProminiA"]["pin_mode"]["analog_output"]={"a_out":[(9)]}

hardwareModelDict["Plug6way"]={"hwName":"Plug6way","max_pin":18,"hardware_type":"arduino_promini","pin_mode":{},"timeout":70}
hardwareModelDict["Plug6way"]={"hwName":"Plug6way","max_pin":18,"hardware_type":"arduino_promini","pin_mode":{},"timeout":90}
hardwareModelDict["Plug6way"]["pin_mode"]["sr_relay"]={"socket":[(2,3),(4,5),(6,7),(8,9),(14,15)],"wifi":[(16,17)]}


Expand Down
3 changes: 2 additions & 1 deletion scripts_folder/hw_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ def getLastNodeSync(self):

def getNodeTimeout(self):
"""| Return the time after which the node is declared inactive.
| So if getLastNodeSync() is greater than this self.timeout the node will be setted as inactive """
| So if getLastNodeSync() is greater than this self.timeout the node will be setted as inactive
| self.timeout is readed from hardwareModelDict in globalVar.py"""
return(self.timeout)

def setNodeActivity(self,value):
Expand Down
5 changes: 3 additions & 2 deletions scripts_folder/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5252,8 +5252,8 @@ def hardwareHandlerThread(): #check the nodes status and update the webobjects
continue #skip

nodeDict[a].setNodeActivity(0) #set the node as inactive
print "the node:"+a+" IS NOT CONNECTED ANYMORE,did you disconnected it?"
errorQueue.put( "The node:"+a+" IS NOT CONNECTED ANYMORE,did you disconnected it?"+"at:" +getErrorTimeString())
print "the node:"+a+" IS NOT CONNECTED ANYMORE,did you disconnect it?"
errorQueue.put( "The node:"+a+" IS NOT CONNECTED ANYMORE,did you disconnect it?"+"at:" +getErrorTimeString())
for b in object_dict.keys():
if object_dict[b].getHwNodeSerialNumber()==a : #if the web object is from the node a then disactive it
#object_dict[b].setStatus("inactive")
Expand All @@ -5263,6 +5263,7 @@ def hardwareHandlerThread(): #check the nodes status and update the webobjects
if nodeDict[a].getNodeActivity()==0: #the node was not connected but now it is
nodeDict[a].setNodeActivity(1) #set the node as active
print "node:"+a+" returned active"
errorQueue.put( "The node:"+a+" IS NOW RECONNECTED "+"at:" +getErrorTimeString())
for b in object_dict.keys():
print "object_dict[b].getHwNodeSerialNumber():"+str(object_dict[b].getHwNodeSerialNumber())
if object_dict[b].getHwNodeSerialNumber()==a : #if the web object is from the node a then reactive it
Expand Down
2 changes: 1 addition & 1 deletion to_do.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ sudo md5sum -c checksum2.md5

3.7) Gestione carichi e pannelli solari,lettura contatore enel

4) Sviluppo nodi wireless con wifi o altro modulo wireless
4) Sviluppo nodi wireless con wifi o altro modulo wireless , sviluppo gestore indirizzi e

5) Cercare di permettere all'utente di scrivere nomi non ashii per gli oggetti, gli scenari,gli utenti...

Expand Down

0 comments on commit a5d0bc0

Please sign in to comment.