Go Down

Topic: react on incomming messages (SOLVED) (Read 2822 times) previous topic - next topic

jarivds_010

May 19, 2020, 09:32 am Last Edit: May 26, 2020, 09:40 am by jarivds_010
Here is the problem. I have build a ttn network based project. I can send to the things network which will send it over http to a php file and then to a database. But when I send a message back it gets back the whole way to the arduino but i don't know how I can do something with that data. In the lora send and recieve tutorial you can only read out messages in your serial monitor. How can I transform that incomming message to a function. For example put a led on and off.

here is my recieving part of the code:

Code: [Select]

if (!modem.available()) {
      Serial.println("No downlink message received at this time.");
    }

  char rcv[64];
  int i = 0;
  while (modem.available()) {
    rcv[i++] = (char)modem.read();
  }

 
  Serial.println("Received: ");
  for (unsigned int j = 0; j < i; j++) {
    Serial.print(rcv[j] >> 4, HEX);
    Serial.print(rcv[j] & 0xF, HEX);
    Serial.print(" ");
  }
  Serial.println();



From this part I tried something but this doesn't work. You see what i'm trying to do?

Code: [Select]


  char cont = Serial.read();
  Serial.println(cont);
  if(cont == 'exact message I send from ttn'){
    digitalWrite(flitser, HIGH);
    digitalWrite(sirene, HIGH);
  }

jarivds_010


jarivds_010

#2
May 26, 2020, 09:38 am Last Edit: May 26, 2020, 09:41 am by jarivds_010
I fixed the problem. Was quite simple, but didn't know how to do it

Code: [Select]

while (modem.available()) {
rcv = (byte)modem.read();
}


Serial.println("Received: ");
Serial.println(rcv);


if(rcv == 116){
digitalWrite(flitser, LOW);
digitalWrite(sirene, LOW);
}


So I read what the recieved number is and if that is the same in a byte format you can trigger the parts

Go Up