Hello Guys!
I am trying to control an impulse relay over internet.
My code isn't hard since I am rookie, but I keep getting error that I can not surpass. I have searched through this forum and found similar topics (for example this one), but it doesn't work for me.
I am reading MySQL database, and I want according to a value to turn selected GPIO.
Where I have a problem is that I can not compare the JSON variable with integer nor char.
I keep getting this message:
ambiguous overload for 'operator==' (operand types are 'JSONVar' and 'int')
I tryed to convert the variable to integer, or string or char but it doesn't work.
I get only different error naming that other variable.
JSONVar keys = myObject.keys();
JSONVar value = int (myObject[keys[0]]);if (value==0){
Serial.print("GPIO: ");
Serial.print(keys[0]);
Serial.println(value);
pinMode(26, OUTPUT);
digitalWrite(26, HIGH);
delay(100);
digitalWrite(26, LOW);
}if (value==1){
Serial.print("GPIO: ");
Serial.print(keys[1]);
Serial.println(value);
pinMode(27, OUTPUT);
digitalWrite(27,HIGH);
delay(100);
digitalWrite(27, LOW);
}else {
Serial.println("Error");
}
I am using this JSON library
#include <Arduino_JSON.h>
I have also tried doing it like this:
JSONVar keys = myObject.keys();
JSONVar value = myObject[keys[0]];
intVal = int(value);
if (intVal==0){Serial.print("GPIO: ");
Serial.print(keys[0]);
Serial.println(intVal);
pinMode(26, OUTPUT);
digitalWrite(26, HIGH);
delay(100);
digitalWrite(26, LOW);
}
if (intVal==1){Serial.print("GPIO: ");
Serial.print(keys[1]);
Serial.println(intVal);
pinMode(27, OUTPUT);
digitalWrite(27,HIGH);
delay(100);
digitalWrite(27, LOW);
}
else {
Serial.println("Error");
}
I have also tryed by usind switch..case, and it doesn't give me error, but it reads the "intVal" as 0 no matter if it changed in the database to 1. As if I can not convert it to anything else but 0. :![]()