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.