I am working with Node A [Matlab+Xbee (S1)] in one side and Node B [Arduino UNO+Xbee(S1)] on another side. I am trying to send one message [message 1] from Node A to Node B, Node B would get the message1, read it and send another message [message 2] to Node A.
According to my code below, Node B stops sending the message after once, but I want it to continuously send Node A the message. If I separate receiving and sending portion, the problem occurs is as temperature sensor is always reading data, even whenever Node B is not getting any data (in serial port), it is sending the temperature reading encrypted with previous stored key. But I want that no data would be sent from Node B unless it gets a data from Node A at first. Then Node B would start sending data iteratively to Node A. What I should change in the code below to achieve this?
Code:
char key = 'QD98750';
void loop()
{
while (Serial.available ( ) ) {
char c = Serial.read ();
readString += c;
}
if (readString.length() >0) {
char ssid[3] ;
readString.toCharArray (ssid, 3) ;
aes_decryption(key, ssid);%the result is aes_value
key = aes_value;
readString ="" ;
%temperature sensor reading
int reading = analogRead(sensorPin);
float voltage = reading * 5.0;
voltage /= 1024.0;
float temperatureC = (voltage - 0.5) * 100 ;
aes_encryption(key, temperatureC);%the output is aes_value;
Serial.print (aes_value) ;
}
}