Set GPIO pin state when an HTTP request is made

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
BigKnight
New user
Posts: 2
Joined: 29 Mar 2018, 21:26

Set GPIO pin state when an HTTP request is made

#1 Post by BigKnight » 30 Mar 2018, 17:24

Recently I started with ESPEASY to see if it can replace my custom made code that I wrote for my project.

I have a ESP (Wemos D1 mini R2) with 2 sensors, DS18B20 and a Thermocouple and 2 LEDs. I'll be using them to measure the temperatures of a swimming pool heater.

Current working setup (with own code):
- DS18B20
- Thermocouple
- 1 colored led that turns on and stays on when the ESP is connected to WiFi
- 1 colored led that blinks when my webserver is doing an HTTP request.

I managed to get the first 3 bullets working with ESPEasy, adding the sensors was easy and I found a Rule on the Wiki to set a GPIO pin to HIGH when connected to WiFi:
on WiFi#Connected do
GPIO,13,1
endon

For the last bullet i need help. My webserver is requesting the JSON output every 10 seconds and stores the values in a database.
Is there any way i can set a GPIO pin to HIGH when the ESP gets a request for about 1 second and then to LOW again, so I can have the LED blink. That way I know the setup is working ok, instead of checking the DB or the ESP logs.

Any help is appreciated.

kimot
Normal user
Posts: 190
Joined: 12 Oct 2017, 20:46

Re: Set GPIO pin state when an HTTP request is made

#2 Post by kimot » 31 Mar 2018, 16:45

And how your webserver requested data from ESPeasy?

If it send some event command, then in this event set LED gpio on and set some some timer.
On this timer event then set LED gpio off.
Or send pulse to LED gpio.

BigKnight
New user
Posts: 2
Joined: 29 Mar 2018, 21:26

Re: Set GPIO pin state when an HTTP request is made

#3 Post by BigKnight » 01 Apr 2018, 21:07

The webserver requests the URL like this:

<?php

$url = "http://192.168.178.31/json";
$json = file_get_contents($url);
$json_data = json_decode($json, true);

//rest of code
?>

Then I just read the needed values from the array

I checked the syslog, but can't see any incoming event when I execute the script.

kimot
Normal user
Posts: 190
Joined: 12 Oct 2017, 20:46

Re: Set GPIO pin state when an HTTP request is made

#4 Post by kimot » 02 Apr 2018, 16:30

Maybe call something like this:

http://192.168.178.31/control?cmd=event,led_blink

Before or after your http://192.168.178.31/json

and write event "led_blink", which blinks led.

Or send http://<espeasyip>/control?cmd=Pulse,14,1,500
where 14 is GPIO number and 500 are milisecond.

https://www.letscontrolit.com/wiki/inde ... O#Commands

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 10 guests