Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word "OK" at the end of the JSON status GPIO #3221

Closed
Pierre89 opened this issue Aug 18, 2020 · 3 comments
Closed

Word "OK" at the end of the JSON status GPIO #3221

Pierre89 opened this issue Aug 18, 2020 · 3 comments

Comments

@Pierre89
Copy link

Pierre89 commented Aug 18, 2020

Hello, since the ESPEASY MEGA version, when you check the status of a GPIO, a JSON appears like this : /control?cmd=Status,GPIO,12

{
"log": "",
"plugin": 1,
"pin": 12,
"mode": "output",
"state": 0
}

Ok

on previous versions of ESPEASY, for example ESPEasy_v2.0.0-dev11, there was no "OK" word at the end of the JSON. This word bothers me because in php JSON_DECODE can no longer function correctly because of the word.

Normally, a json remains a json. The "OK" has nothing to do here it comes out of the object it's dirty.

otherwise I have to do a str_replace "OK" by "" it's not clean...
can you tell me why "OK" is here? How do I get my PHP code to work ? My code is

$json = file_get_contents("http://mysonoff/control?cmd=Status,GPIO,12");

$array = json_decode($json, true);

if ($array["state"] === 0) {
echo "OMG my sonoff is OFF";
} else {
echo 'OH YES my sonoff is ON';
fclose;
}

Thanks x)

@ironataerial
Copy link

#2892

@Pierre89
Copy link
Author

Pierre89 commented Aug 18, 2020

#2892

thanks, my best solution is :

$json = file_get_contents("http://mysonoff/control?cmd=Status,GPIO,12");

$json = str_replace( "Ok", ' ', $json );

$array = json_decode($json, true);

if ($array["state"] === 0) {
echo "OMG my sonoff is OFF";
} else {
echo 'OH YES my sonoff is ON';
fclose;
}

@giig1967g
Copy link
Contributor

#2778 will fix it.
The PR is in the queue to be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants