diff --git a/BaseStation/unoserver2/unoserver2.ino b/BaseStation/unoserver2/unoserver2.ino index 0836758..2b25018 100644 --- a/BaseStation/unoserver2/unoserver2.ino +++ b/BaseStation/unoserver2/unoserver2.ino @@ -286,9 +286,9 @@ void loop() // The RFM_SEND switch above loads the RFM_SEND command in // TX_payload queue. readRFM69() call below is the one which // should POP out the payload from TX_payload (it's a 2D array), - if ((msg = readRFM69())!=NULL) + if (readRFM69()!=0) { - Serial.println(msg); + Serial.println(str.buf); str.reset(); } } @@ -327,12 +327,34 @@ static void rfwrite(const Payload& P) { { rf12_sleep(-1); //wake up RF module - while (!rf12_canSend()) rf12_recvDone(); - rf12_sendStart(0, &P, sizeof P); - rf12_sendWait(1); //wait for RF to finish sending while in IDLE (1) mode (standby is 2 -- does not work with JeeLib 2018) + + int i=0; + while (!rf12_canSend()) {rf12_recvDone();i++;} rf12_sendStart(0, &P, sizeof P); rf12_sendWait(1); //wait for RF to finish sending while in IDLE (1) mode (standby is 2 -- does not work with JeeLib 2018) + // rf12_sendStart(0, &P, sizeof P); + // rf12_sendWait(1); //wait for RF to finish sending while in IDLE (1) mode (standby is 2 -- does not work with JeeLib 2018) // rf12_sleep(0); //put RF module to sleep + + // int i=0; + // for(i=0;i<100;i++) + // if (rf12_canSend()) + // { + // // while (!rf12_canSend()) rf12_recvDone(); + // rf12_sendStart(0, &P, sizeof P); + // rf12_sendWait(1); //wait for RF to finish sending while in IDLE (1) mode (standby is 2 -- does not work with JeeLib 2018) + // rf12_sendStart(0, &P, sizeof P); + // rf12_sendWait(1); //wait for RF to finish sending while in IDLE (1) mode (standby is 2 -- does not work with JeeLib 2018) + // // rf12_sleep(0); //put RF module to sleep + // break; + // } + // else + // { + // rf12_recvDone(); + // delay(10); + // } + // if (i > 0) + // Serial.println("{\"rf_fail\":1,\"source\":\"ERROR RFM_SEND\",\"Try\":"+String(i)+(" }\0")); } } //#################################################################### @@ -412,7 +434,7 @@ static bool processACK(const int rx_nodeID, const int rx_rx, const int rx_supply #define RX_HDR_OK() (((rf12_hdr & RF12_HDR_CTL) == 0)) #define RX_NODEID() ((rf12_hdr & 0x1F)) -static char* readRFM69() +static byte readRFM69() { int payload_nodeID=NOTHING_TO_SEND; bool isACK=false; @@ -456,7 +478,8 @@ static char* readRFM69() lastPktSent[listenerNdx] = millis(); TX_counter[listenerNdx]++; } - return (str.fill==0)?NULL:str.buf; + // return (str.fill==0)?NULL:str.buf; + return str.fill; } //#################################################################### void writeOne() diff --git a/RPi/NaaradServer/NewServer/NaaradTopic2.py b/RPi/NaaradServer/NewServer/NaaradTopic2.py index 9f3522b..7ce40d9 100644 --- a/RPi/NaaradServer/NewServer/NaaradTopic2.py +++ b/RPi/NaaradServer/NewServer/NaaradTopic2.py @@ -33,9 +33,10 @@ def __init__(self, name, uno, pktHndlr, hLength=6*60*60*1000.0): # topicsSubscriberList["SensorDataSink"]). def run(self): while 1: + line=""; try: - line =self.uno.readline().rstrip(); - except (AttributeError, UniocodeDecodeError) as excpt: + line =self.uno.myreadline().rstrip(); + except (AttributeError, UnicodeDecodeError) as excpt: print("Could not decode to utf-8: %s" %excpt); line=""; #line =self.uno.getSerial().readline(); @@ -56,13 +57,13 @@ def run(self): print("@@@: "+line); #line = self.pktHndlr.addTimeStamp(line); - line = Utils.addTimeStamp("time",line); #print("###: "+line); rlock = threading.RLock(); with rlock: try: if (("rf_fail" in line)): + line = Utils.addTimeStamp("time",line); jdict = json.loads(line);# The JSON parser # print jdict; diff --git a/RPi/NaaradServer/NewServer/comPort.py b/RPi/NaaradServer/NewServer/comPort.py index 0730420..d01bc43 100644 --- a/RPi/NaaradServer/NewServer/comPort.py +++ b/RPi/NaaradServer/NewServer/comPort.py @@ -2,6 +2,7 @@ #Arduino (UNO in this case) related code lives here. # import serial as serial; +#from __future__ import print_function class comPort: ''' @@ -19,6 +20,9 @@ def __init__(self, port='/dev/ttyACM0', baudrate=19200): self.com1.bytesize=serial.EIGHTBITS; self.com1.parity=serial.PARITY_NONE; self.com1.stopbits=serial.STOPBITS_ONE; + self.com1.timeout=10; + self.SOF = '{'; + self.EOF = '}'; def getSerial(self): return self.com1; @@ -35,7 +39,37 @@ def send(self,str): self.com1.write((str+"\n").encode()); def read(self,errors='ignore'): - return self.com1.read().decode(errors=errors); + #return self.com1.read().decode(errors=errors); + return self.com1.read().decode(); def readline(self,errors='ignore'): - return self.com1.readline().decode(errors=errors); + #return self.com1.readline().decode(errors=errors); + print("Waiting..."); + tt=self.com1.readline().decode(); + print("### "+str(tt)); + return tt; + + def myreadline(self): + # FIND START OF FRAME + sensor_data=""; + temp=""; + temp=self.com1.read().decode(); + if (temp==""): + print("TO"); + return temp; + + while (temp != self.SOF): + # print(temp,end=''); + #print('!'+temp); + temp=self.com1.read().decode(); + + # RECORD UNTIL END OF FRAME + # print(temp,end=''); + while (temp != self.EOF): + sensor_data += str(temp); + temp = self.com1.read().decode(); + # print(temp,end=''); + + sensor_data += str(temp); + return sensor_data; + diff --git a/RPi/NaaradServer/NewServer/naarad.py b/RPi/NaaradServer/NewServer/naarad.py index a49a2a2..33de0ea 100644 --- a/RPi/NaaradServer/NewServer/naarad.py +++ b/RPi/NaaradServer/NewServer/naarad.py @@ -41,6 +41,7 @@ def initNaarad(): #uno=comPort(port=settings5.NAARAD_COMPORT,baudrate=9600); uno=comPort(port=settings5.NAARAD_COMPORT); uno.open(); + time.sleep(1); # # Instantiate the object that encapsulates communcation to the packet # radio (RFM64CW) connected to UNO.