Skip to content

Commit

Permalink
working on onos lamp node
Browse files Browse the repository at this point in the history
  • Loading branch information
marco committed Sep 1, 2016
1 parent c418df3 commit 0447ce2
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 100 deletions.
99 changes: 69 additions & 30 deletions arduino_code/onos_lamp_node.ino
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ char node_fw[]="5.13";

int this_node_address=254; //i start with 254

int old_address=254;

unsigned long get_address_timeout=0;

#define rx_msg_lenght 31
# define gateway_address 1

char received_message_type_of_onos_cmd;
char received_message_flag;
Expand All @@ -87,6 +90,9 @@ char received_message_answer[rx_msg_lenght+6]="er00_#]";
char received_message_sn[13]="";
int received_message_address=0; //must be int..

char syncMessage[28];
char str_this_node_address[4];

uint8_t counter;
boolean enable_answer_back=0;

Expand All @@ -101,37 +107,21 @@ int freeRam ()



void syncMessage(){

// onos_s3.05v1sProminiS0001f001_#]
void makeSyncMessage(){

char syncMessage[serial_msg_lenght+3];
char str_this_node_address[4];
//[S_001sy3.05ProminiS0001_#]

str_this_node_address[0]=(this_node_address/100)+'0';
str_this_node_address[1]=(this_node_address/10)+'0';
str_this_node_address[2]=(this_node_address/1)+'0';

strcpy(syncMessage, "onos_s ");
strcpy(syncMessage, "[S_");
strcat(syncMessage, str_this_node_address);
strcat(syncMessage, "sy");
strcat(syncMessage, node_fw);
strcat(syncMessage, "v1s");
strcat(syncMessage, serial_number);
strcat(syncMessage, "f");
strcat(syncMessage, str_this_node_address);

strcat(syncMessage, "_#]");

for (uint8_t pointer = 0; pointer <= serial_msg_lenght; pointer++) {
Serial.print(syncMessage[pointer]);

if ((syncMessage[pointer-1]=='#')&&(syncMessage[pointer]==']') ) {//
break;
}
}
Serial.print('\n');



}


Expand All @@ -141,33 +131,41 @@ void syncMessage(){

void getAddressFromGateway(){

char syncMessage[serial_msg_lenght+3];
char str_this_node_address[4];
//[S_001ga3.05ProminiS0001_#]
makeSyncMessage();



while
syncMessage[6]='g'; //modify the message to get a address instead of just sync.
syncMessage[7]='a'; //modify the message to get a address instead of just sync.

syncMessage[5]='g'; //modify the message to get a address instead of just sync.
if (radio.sendWithRetry(gateway_address, syncMessage, strlen(syncMessage),10,200)) {
if (radio.sendWithRetry(gateway_address, syncMessage, strlen(syncMessage),10,500)) {
//target node Id, message as string or byte array, message length,retries, milliseconds before retry
//(uint8_t toAddress, const void* buffer, uint8_t bufferSize, uint8_t retries, uint8_t retryWaitTime)
Serial.println("sent_get_address");
Blink(LED, 50, 3); //blink LED 3 times, 50ms between blinks
}

syncMessage[5]='s'; //modify the message back to original to just sync.
syncMessage[6]='s'; //modify the message to get a address instead of just sync.
syncMessage[7]='y'; //modify the message to get a address instead of just sync.

//decode message


/*
if (radio.receiveDone())
{
//print message received to serial
Serial.print('[');Serial.print(radio.SENDERID);Serial.print("] ");
Serial.print((char*)radio.DATA);
Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]");
//check if received message contains Hello World
if (strstr((char *)radio.DATA, "Hello World"))
//check if received message contains address
//[S_123sa3.05ProminiS0001_#]
if( (strstr((char *)radio.DATA[6],'s'))&&(strstr((char *)radio.DATA[7],'a') ) )
{
//check if sender wanted an ACK
if (radio.ACKRequested())
Expand All @@ -179,6 +177,8 @@ void getAddressFromGateway(){
}
}
*/

radio.receiveDone(); //put radio in RX mode


Expand All @@ -189,6 +189,8 @@ void getAddressFromGateway(){


void setup() {


while (!Serial); // wait until serial console is open, remove if not tethered to computer
Serial.begin(SERIAL_BAUD);

Expand Down Expand Up @@ -218,6 +220,43 @@ void setup() {
}

void loop() {


if (old_address==254){// i have not the proper address yet..



if (old_address!=this_node_address){//the address has changed and i restart radio to use it

radio.initialize(FREQUENCY,NODEID,this_node_address);
if (IS_RFM69HCW) {
radio.setHighPower(); // Only for RFM69HCW & HW!
}
radio.setPowerLevel(31); // power output ranges from 0 (5dBm) to 31 (20dBm)

radio.encrypt(ENCRYPTKEY);
old_address=this_node_address;
get_address_timeout=millis();

}



if ((millis()-get_address_timeout)>500){ //every 500 ms

get_address_timeout=millis();

getAddressFromGateway(); //ask the gateway for a proper address




}


}


//check if something was received (could be an interrupt from the radio)
if (radio.receiveDone())
{
Expand Down
10 changes: 5 additions & 5 deletions arduino_code/onos_rf69_serial_transponder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ int freeRam ()



void sendSyncMessage(){
void makeSyncMessage(){

// onos_s3.05v1sProminiS0001f001_#]
char syncMessage[rx_msg_lenght+3];
Expand Down Expand Up @@ -751,12 +751,12 @@ void loop()



unsigned long t=millis();
if ( (t-sync_time)>12000){ //each 120 sec time contact the onosCenter and update the current ip address
sync_time=t;

if ( (millis()-sync_time)>12000){ //each 120 sec time contact the onosCenter and update the current ip address
sync_time=millis();
// onos_s3.05v1sProminiS0001f001_#]

sendSyncMessage();
makeSyncMessage();

}

Expand Down
65 changes: 0 additions & 65 deletions arduino_code/rf69_reliable_datagram_server.pde

This file was deleted.

3 changes: 3 additions & 0 deletions tests/problems_and_solutions
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ I will use post instead that get message
12 byte to tell the node serial number
3 bytes with "_#]" to close the message
example: [S_001ga3.05ProminiS0001_#]

OnosCenter will answer witha : [S_123sa3.05ProminiS0001_#] to tell the node to set its address to 123 for example




Expand Down

0 comments on commit 0447ce2

Please sign in to comment.