-->
Page 1 of 1

Initiate code by URL load rather than form submission

PostPosted: Mon Dec 04, 2017 2:04 am
by Bitpod
Hi,

I have some code that currently builds a webpage to initiate the action via a web page button press. I would like to adapt this code to instead be triggered by some VB script on another pc (on the same network) e.g. by something like...

Code: Select allDim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString("http://IP-of-Ardduino/buttonpress")

The micropython I have at the moment is
Code: Select allwifi.setmode(wifi.STATION)
wifi.sta.config("SSID","WiFipassword")
print(wifi.sta.getip())
pin_out = 3
US_TO_MS = 1000
gpio.mode(pin_out, gpio.OUTPUT)
gpio.write(pin_out, gpio.HIGH)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
    conn:on("receive", function(client,request)
        local buf = "";
        local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
        if(method == nil)then
            _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
        end
        local _GET = {}
        if (vars ~= nil)then
            for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
                _GET[k] = v
            end
        end
        buf = buf.."<h1> ESP8266 Web Server</h1>";
        buf = buf.."<p>GPIO0 <a href=\"?pin=SND\"><button>Send Key</button></a></p>";
        local _on,_off = "",""
        if(_GET.pin == "SND")then
              gpio.write(pin_out, gpio.HIGH);
              tmr.delay(200 * US_TO_MS);
              gpio.write(pin_out, gpio.LOW);
        end
        client:send(buf);
        client:close();
        collectgarbage();
    end)
end)

If anyone could help me amend the above micropython code to work like this I would be most grateful.

Alex