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.
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.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
- k_su
- Posts: 2
- Joined: Fri Sep 08, 2017 3:22 pm
- adafruit_support_mike
- Posts: 67391
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Adabox 003, digital IO output. Toggle only outputs LOW
[moved to the adafruit.io forum]
- tomis4cd
- Posts: 68
- Joined: Wed Mar 14, 2012 1:02 pm
Re: Adabox 003, digital IO output. Toggle only outputs LOW
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
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
- abachman
- Posts: 352
- Joined: Mon Feb 01, 2010 12:48 pm
Re: Adabox 003, digital IO output. Toggle only outputs LOW
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: 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
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;
}
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
- kpu979
- Posts: 4
- Joined: Wed May 02, 2018 9:51 pm
Re: Adabox 003, digital IO output. Toggle only outputs LOW
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.
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.