Go Down

Topic: gsm temperature setting (Read 289 times) previous topic - next topic

matios95

Apr 20, 2019, 04:12 pm Last Edit: Apr 21, 2019, 03:07 pm by matios95
hi guys.
im new in arduino and i want build a temperature monitor system with gsm sim800l and ds18b20.

I found a code in web and I do not understand some of its parts. Thank you for your advice


Code: [Select]

num = gsm_data.indexOf(MasterNUM);

  if (num > -1) {
    if ( (gsm_data.indexOf("temp?")) > -1) {
      currenttemp = 1;
    }
    if ( (gsm_data.indexOf("R1:1")) > -1) {
      state1 = 1;
      EEPROM.write(0, 1);
      digitalWrite(output1, HIGH);
      UpdateSMS = 1;
      str1 = "state1: ";
      str1 += state1;
    }
    if ( (gsm_data.indexOf("R1:0")) > -1) {
      state1 = 0;
      EEPROM.write(0, 0);
      digitalWrite(output1, LOW);
      UpdateSMS = 1;
      str1 = "state1: ";
      str1 += state1;
    }
    if ( (gsm_data.indexOf("R2:1")) > -1) {
      state2 = 1;
      EEPROM.write(1, 1);
      digitalWrite(output2, HIGH);
      UpdateSMS = 1;
      str2 = "  state2: ";
      str2 += state2;
    }
    if ( (gsm_data.indexOf("R2:0")) > -1) {
      state2 = 0;
      EEPROM.write(1, 0);
      digitalWrite(output2, LOW);
      UpdateSMS = 1;
      str2 = "state2: ";
      str2 += state2;
    }


what is question mark in line 3 after Temp "Temp?" ?
and
what is R1,R2 and where we can define it?

cattledog

#1
Apr 20, 2019, 11:21 pm Last Edit: Apr 20, 2019, 11:24 pm by cattledog
Welcome to the forum. You will have more success in getting your questions answered if you use the code tags to post your code.



Please read the How to Use the Forum for more advice. http://arduino.cc/forum/index.php/topic,148850.0.html

Your code appears to read a String gsm_data and then proceeds to check if various elements are in the received message."Temp?" "R1:1"  and "R2:2" are all parts of the message in the example you are partially citing.

matios95

Welcome to the forum. You will have more success in getting your questions answered if you use the code tags to post your code.



Please read the How to Use the Forum for more advice. http://arduino.cc/forum/index.php/topic,148850.0.html

Your code appears to read a String gsm_data and then proceeds to check if various elements are in the received message."Temp?" "R1:1"  and "R2:2" are all parts of the message in the example you are partially citing.
im new. Thank you for your reminder. You are right but No place codes for these variables are defined. R1 and R2 seem to be constant variables. Can you find out about the question mark "?" and the quote "?" in IF structure?
thank u.

cattledog

#3
Apr 21, 2019, 04:02 pm Last Edit: Apr 21, 2019, 04:03 pm by cattledog
Quote
You are right but No place codes for these variables are defined. R1 and R2 seem to be constant variables. Can you find out about the question mark "?" and the quote "?" in IF structure?
You have posted incomplete code from an example you evidently do not understand. Cut and paste programming often leads to confusion. You are better off working slowly through some SIM800l tutorials until you understand more about what you are doing. The code is also using String methods which can lead to memory issues with small microprocessors.
https://hackingmajenkoblog.wordpress.com/2016/02/04/the-evils-of-arduino-strings/


Quote
Your code appears to read a String gsm_data and then proceeds to check if various elements are in the received message."Temp?" "R1:1"  and "R2:1" are all parts of the message in the example you are partially citing.
What part of this answer did you not understand? What message are you sending? What does it mean if it contains "Temp?" "R1:1" "R2:0"?

If you want the receiver of the message to use them as variables they need to be defined in the receiving program.

Quote
Can you find out about the question mark "?" and the quote "?" in IF structure?
[/quote]

The code snippet you posted appears to do that by testing the String for the index(location) of the text in quotes   "Temp?" "R1:1"  and "R2:1"

Code: [Select]

if ( (gsm_data.indexOf("temp?")) > -1)
if ( (gsm_data.indexOf("R1:0")) > -1)
if ( (gsm_data.indexOf("R1:1")) > -1)
if ( (gsm_data.indexOf("R2:1")) > -1)
if ( (gsm_data.indexOf("R2:0")) > -1)

Go Up