REST API Can not Read Digital PIN (ESP8266)

Yes ā€¦ I think Iā€™ve tried the correct PIN ā€¦ I tried several D PIN and all resulting the same ā€¦

Just tried and same result ā€¦

And if you are trying to toggle the state of that pinā€¦ try this way (the Write pin value via GET method) ā€¦

http://192.168.0.23:8080/<my-auth-token>/update/D14?value=0
http://192.168.0.23:8080/<my-auth-token>/update/D14?value=1

But againā€¦ make sure you are using the correct board type in your App, as the API uses that device selection to ā€œmap outā€ the proper pin.

BTW, this was all discussed just a day or so ago hereā€¦

According to the link you gave: ESP8266 should be like this:

    "name": "ESP8266",
    "map": {
        "digital": {
            "pins": {
                "gp0":  0,  "gp1":  1,  "gp2":  2,  "gp3":  3,  "gp4":  4,
                "gp5":  5,
                                        "gp12": 12, "gp13": 13, "gp14": 14,
                "gp15": 15, "gp16": 16
            },
            "ops": [ "dr", "dw" ]
        },
        "analog": {
            "pins": {
                "adc0": 17
            },
            "ops": [ "ar" ],
            "arRange": [ 0, 1023 ]
        },
        "pwm": {
            "pins": [
                "gp0", "gp1", "gp2", "gp3", "gp4", "gp5", "gp12", "gp13", "gp14", "gp15"
            ],
            "ops": [ "aw" ],
            "awRange": [ 0, 1023 ]
        },
        "virtual":  {
            "pinsRange": [ 0, 127 ],
            "ops": [ "vr", "vw" ]
        }
    }
}```


Unfortunately when I tried gp14 or gp5 it does not recognised :frowning:

To confirm, you are trying to READ the state of a digital pin (silkscreened D5 - GPIO14) probably from a NodeMCU or Wemos Di Miniā€¦ correct?

1 Like

Iā€™ve just tried:

http://192.168.0.23:8080/<my-auth-token>/update/D14?value=0
http://192.168.0.23:8080/<my-auth-token>/update/D14?value=1

And surprisingly work like a charm :slight_smile:

But have no luck on :
http://192.168.0.23:8080/<my-auth-token>/get/D14

I am testing on my Mega based testbench, and getting the same errorā€¦ and with the Mega there is no discrepanciesā€¦ the button on D12 is digital pin 12, AKA GPIO12, AKA API D12ā€¦

image

Further testingā€¦

Yes, correct a NodeMCU 8266

I will test on my NodeMCU then and report backā€¦

1 Like

Really appreciate with your time dude ā€¦ Iā€™m doing some digging also here ā€¦

OK, while I can toggle pins, I can NOT read them, on Arduino or NodeMCUā€¦

On the NodeMCU while entering different pins from D1 and up, I get the rare ā€œ1ā€ or ā€œ128ā€ but mostly the ā€œRequested pin not exists in app.ā€, and when I can get a value, it doesnt change when the supposed pin state changesā€¦

I have tried Generic board, ESP8266 and NodeMCUā€¦ all same results.

I am starting to see how this supposedly RESTful API is causing some to lose sleep :stuck_out_tongue_winking_eye:

OK, back to the RED Issues and Errors categoryā€¦ something appears quirky with this API

@Dmitriy take a look

@noersaleh All Right!.. Preliminary tests with a clean Project point out what I guess is obvious, after the fact :blush: ā€¦ but not documented that I am aware of (as far as the API is concerned).

If you donā€™t have a widget assigned to a digital pin, it will register as ā€œRequested pin doesnā€™t exist in the app.ā€ā€¦ or possibly a random, unchangeable, state.

But if you then assign a widget/reading rate to a digital pin, then the API GET command will read the corresponding pin state [ā€œ0ā€] or [ā€œ1ā€].

The key is that you MUST have an pin assigned widget!.. vPin for Vpin reading, GPIO assigned for Dpin (or Apin) reading.

Toggling a digital pin however WILL work without a widget assigned to the pinā€¦ at least with the Write pin value via GET methodā€¦ go figure.

1 Like

@Gunner
Thanks, the fact is that I have tried to add a Digital pin (D5 or GPIO14) on a Widget on my Blynk apps (and tested working from Blynk apps), but sill have the same problem on REST API ā€¦

I donā€™t know what you have, but this is what seems to work for my testā€¦

image

image

And of course, if no widget assigned ā€œin the appā€ā€¦ GPIO14

image

I guess the question for the developers isā€¦ how do you READ a pin via API on a device that is not assigned a widget, much like it is possible to WRITE to an unassigned pin?

@Gunner Try something like this, which is a catch-all for unassigned handlers.

//
// This is called for all virtual pins that do not have BLYNK_READ handler
//
BLYNK_READ_DEFAULT()
{
    terminalWidget.print("BLYNK_READ for pin ");
    terminalWidget.print(request.pin);
    terminalWidget.println(" not defined.");
    terminalWidget.flush();
}

Yesā€¦ while I havenā€™t tried with the API, I have played around with the BLYNK_READ_DEFAULT() function.

One limitation seems to be that it is a one-shot type deal AKA it will work for any unassigned pin, but it will only do the same thing (whatever you program in the function) regardless of the pinā€¦ and you cannot seem to have multiple functions.

So more a default error catch then a usable multi-pin multi-use solution.

Besides, it wasnā€™t an issue with an unassigned vPin as much as one that was assigned (in code) just not associated with a widget in the App. The solution is simply associate a widget, any widget, even if never used in the App.