Adabox 003, digital IO output. Toggle only outputs LOW

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
k_su
 
Posts: 2
Joined: Fri Sep 08, 2017 3:22 pm

Adabox 003, digital IO output. Toggle only outputs LOW

Post by k_su »

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.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

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

Post by adafruit_support_mike »

[moved to the adafruit.io forum]

User avatar
tomis4cd
 
Posts: 68
Joined: Wed Mar 14, 2012 1:02 pm

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

Post by tomis4cd »

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

User avatar
abachman
 
Posts: 352
Joined: Mon Feb 01, 2010 12:48 pm

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

Post by abachman »

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

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

User avatar
kpu979
 
Posts: 4
Joined: Wed May 02, 2018 9:51 pm

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

Post by kpu979 »

I Just ran into the exact same issue. The On/Off values HAS TO BE 1/0, otherwise, only 0 is sent no matter what else you enter. And Im sure w are all ok with having this binary on the switch block, but it would be totally awesome if we could label the text any way we want.

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”