0

Adabox 003, digital IO output. Toggle only outputs LOW
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adabox 003, digital IO output. Toggle only outputs LOW

by klas_sundberg on Fri Sep 08, 2017 3:30 pm

So I can connect to my IO account, but when I toggle the switch I get "LOW" in both toggle positions?

Could anybody kindly point me in the direction as to where to look?


to Adafruit IO..........
Adafruit IO connected.
received <- 0
LOW
received <- 0
LOW

(This is the same with or without the zero induced by my fluddering:

void handleMessage(AdafruitIO_Data *data) {

Serial.print("received <- ");

if(data->toPinLevel() == HIGH)
Serial.println("HIGH");
else
Serial.println(data->toPinLevel());
Serial.println("LOW");

// write the current state to the led
digitalWrite(LED_PIN, data->toPinLevel());

}

)

The message dash thinks I'm sending the right things though:

2017-09-08 09:08:44 pmDigitalOFF
2017-09-08 09:08:45 pmDigitalON
2017-09-08 09:13:29 pmDigitalOFF
2017-09-08 09:13:33 pmDigitalON
2017-09-08 09:16:33 pmDigitalOFF
2017-09-08 09:16:34 pmDigitalON


The digital input exercise works as intended btw.

klas_sundberg
 
Posts: 1
Joined: Fri Sep 08, 2017 3:22 pm

Re: Adabox 003, digital IO output. Toggle only outputs LOW

by adafruit_support_mike on Fri Sep 08, 2017 11:19 pm

[moved to the adafruit.io forum]

adafruit_support_mike
 
Posts: 43300
Joined: Thu Feb 11, 2010 2:51 pm

Re: Adabox 003, digital IO output. Toggle only outputs LOW

by tomis4cd on Sat Sep 09, 2017 5:12 pm

Just encountered the same issue.
It appears that the text on the buttons has to be 1 and 0 for it to work.
That is how the guide for adabox003 digital output shows it.
I would have expected you could label each side however you like and
it would send 1 for one side and 0 for the the other in the background
but not so, maybe a bug in the control

Tom

tomis4cd
 
Posts: 50
Joined: Wed Mar 14, 2012 1:02 pm

Re: Adabox 003, digital IO output. Toggle only outputs LOW

by abachman on Tue Sep 12, 2017 4:36 pm

Hi Tom,


You are correct that with the toggle switch the text labels are also the value that is sent. I can see how the labelling on the block editing form isn't clear about that, though. Sorry you ran into trouble. I think for the time being I'll make the block editor clearer rather than adding separate value options or having the toggle always send a particular value for left and right switched.

If you'd like to have different button text and you're using the Adafruit IO Arduino library, though, you could go into the the library code and expand the number of inputs that are recognized as "truthy". Wherever your Arduino libraries are stored, in the Adafruit_IO_Arduino/src/AdafruitIO_Data.cpp file, in the function that looks like "bool AdafruitIO_Data::toBool()" you'll find the logic that actually converts feed values to boolean values. That's what the toPinLevel function is using behind the scenes to decide between HIGH and LOW.

Right now it accepts "1", "t", or "T" as true values. But you could change it to:
Code: Select all | TOGGLE FULL SIZE
bool AdafruitIO_Data::toBool()
{
  if(! _value)
    return false;

  if(strcmp(_value, "1") == 0 || _value[0] == 't' || _value[0] == 'T' || strcmp(_value, "ON") == 0 || strcmp(_value, "on") == 0)
    return true;
  else
    return false;
}
so that "ON" and "on" are also recognized as "truthy" or in your example code's case, toPinLevel() == HIGH, values.

It's likely we'll include that logic in a future library update anyways, since it would make Arduino devices just work with the default dashboard toggle button settings.


- Adam

abachman
 
Posts: 58
Joined: Mon Feb 01, 2010 12:48 pm

Please be positive and constructive with your questions and comments.