Cannot access my device sensors from the console and mobile app

I don’t know why but for some reason, the sensors on my devices that I used to be able to activate/deactivate through the web console and mobile app now doesn’t work:

I have tried to invoke it directly through the devices API but it also keeps on hanging on without returning any result.

After a very long period of time, there’s some kind of response:

Hi,

I was wondering if you are so kind as to show us your device’s code, in order to understand better the situation.

Remember to use the “</>” button to present the code into appropriate way.

BR.

Well, it is quite a straight forward setup and it connects to the internet without any problem.

#include <ThingerESP8266.h>
#include <ESP8266WiFi.h>


#define USERNAME "my_account_name"
#define DEVICE_ID "my_device_id"
#define DEVICE_CREDENTIAL "my_device_cred"


ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
  /// ...
}

#define analogPin A0
int adcValue = 0;  /* Variable to store Output of ADC */
void loop() {
  thing.handle();

  thing[EXTERNALLY_CONTROLLABLE_RESOURCE_ID] << [](pson& in){
    if((bool)in)
      // do stuff
  };

  adcValue = analogRead(analogPin); /* Read the Analog Input value */
  //Serial.println(adcValue);
  /* Print the output in the Serial Monitor */
  if(adcValue >= 160 && adcValue <= 1025) {
    // do stuff
  }
}

I have a 5V relay connected to this controller/device (ESP8266) and I try to open it as you can see here:

thing[EXTERNALLY_CONTROLLABLE_RESOURCE_ID] << [](pson& in){
    if((bool)in)
      // do stuff
  };

In general, I could open the relay by bypassing the whole workflow and directly go to thinger.io console/devices/API and then turn on and off my relay.

But the issue is that it doesn’t show me the relay at all.

SIDE NOTE: If I remove the code for analogue reading from pin A0, it seems to work and the relay is opening.

ANOTHER OBSERVATION: It seems like what causes the issue is this line in the loop:

adcValue = analogRead(analogPin); /* Read the Analog Input value */

How can I work around this? For some reason, this is blocking Thinger.io to understand what are my peripherals.

Hi,

This [quote=“peepnee, post:3, topic:4647”]

thing[EXTERNALLY_CONTROLLABLE_RESOURCE_ID] << [](pson& in){
    if((bool)in)
      // do stuff
  };

[/quote]

Should go at the setup function, not in the loop.

Try it and let us know if it persists the issue.

If it persist, paste the whole code, to see what else could be affecting the behaviour.

Hope this helps.

I moved it to the setup function but it doesn’t solve the problem. What causes the issue (100% sure) is this line of code:

adcValue = analogRead(analogPin); /* Read the Analog Input value */

in the loop function. I need to figure out how this can be fixed. If I remove it from the code - everything works as expected.

What is the best way to read analogue input when using Thinger.io on ESP32/ESP8266?

If you dont share your code it is so dificult for us to imagine what is it happening, so I can do nothing in this situation.

I have had no issues using ADC or other peripheral with those uC, I recognize that I use most the ESP32.

I understand that maybe your code could have intelectual property that you dont want to make public, in this case I recommend you to contact official technical support → Technical Support | Thinger.io

Hope this helps

Hey @peepnee

I think you solved your issue with the last snippet of code. It is actually not an issue with Thinger.io’s console.

Even though it should not be necessary to configure the pinMode for an analog pin, in some cases, setting the pin mode explicitly as INPUT can help ensure proper behavior, especially if the pin has been used previously as an OUTPUT. This is because the pin state can get “stuck” in a certain mode and need to be reset. Additionally, some code libraries or third-party hardware may change the pin mode and not reset it to the default, so explicitly setting the pin mode in your code can ensure the proper behavior in these cases.

Regards