Dear forum
I want to set a pin (LED) from a web browser but I just cannot get this webhook to work, though the setup is ultra simple and I can control the LED from within the Blynk app using a simple button.
- NodeMCU ESP 8266
- Arduino 1.8.8
- Control LED on pin D1 (GPIO5)
I searched a lot and tried many URLs in the browser (the IP I got from a Ping request):
http://139.59.206.133/7170b21b16514b22a9d9241733d51f2f/pin/D1?value=1
http://139.59.206.133/7170b21b16514b22a9d9241733d51f2f/update/D1?value=1
Not workingâŚ
Plain and simple code:
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "7170b21b16514b22a9d9241733d51f2f";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "mySSID";
char pass[] = "myPassword";
int outputPin = 5; // Pin D1
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(outputPin, OUTPUT);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
Is there anybody that can help me? What am I missing?
Thanks and best regards
P.S. Do I need to configure the WebHook widget in the Blynk app? I donât think so, this seems to be for outgoing webhooks to a 3rd party.
A few observationsâŚ
Issue 1
Youâre using a NodeMCU or Wemos D1 Mini, which has labels screen printed on it that say things like D1, D2 etc.
It seems that you want to control the pin thatâs labelled D1, which in the code you correctly identify as GPIO5.
In the Blynk app, youâve probably seen digital pins labelled as D1, D2 etc, and thought that these correlate to the labels screen prinnted on your NodeMCU board. They donât!
The D numbers in the app relate to the GPIO numbers of the pins, not the numbers printed on the board.
When youâre using the API, you also use GPIO numbers, so if youâre trying to control the pin that has D1 printed next to it, you need to use D5 in your API url.
Issue 2
Youâve probably read that if youâre using a service like IFTTT then rather than using the url of blynk-cloud.com you should use use the IP address that you get when you ping blynk-cloud.com from your PC.
This is because the IFTTT server that youâre using could be anywhere in the world and blynk-cloud.com may take it to the wrong Blynk server, in which case it wonât find your project, and give an âinvalid Auth codeâ message.
If youâre doing this from the browser on your PC them blynk-cloud.com will work fine.
If you are using the IP address in your API call then you probably need to append the port onto the end, so 139:59:206:133:8080 is probably what you need.
Have you tried using the API reference console to build your API string:
https://blynkapi.docs.apiary.io/#reference/0/write-pin-value-via-get/set-widget-property-via-get?console=1
Pete.
1 Like
Hi Pete
Thank you VERY much, that solved it, I just needed to write D5 instead of D1 in the webhook and that solved it! Of the 2 statements I mentioned only âŚ/update/⌠worked, not âŚ/pin/âŚ, but at least I got a working solution.
And yes, I tried the API reference console before, itâs not working there, but probably due to the fact that I cannot set the IP address as the hostname blynk-cloud.com is fix (and probably points to another server than mine).
Thanks again for your quick feedback
-MakerAndy
1 Like
Iâm not sure where the /pin/ syntax came from, but Iâd expect to have to replace âpinâ with âD5â anyway.
And to answer an earlier question, you donât need the webhook widget in your app for this to work (although I see that you do have one there at the moment).
Glad its working, Iâll mark the topic as solved.
BTW - donât forget to change your Auth code, otherwise anybody who reads this forum can activate whatever is attached to pin GPIO5.
Pete.
yes, solved. Itâs only a temp test setup with a LED, but I changed the Auth code, thanks again!
1 Like