Project Prerequisites ESP8266 lua finterperter flashing instructions here. Installation of lua scripts to ESP8266 device instructions here. |
I have pieced together my first interface for the internet of things.
Today I am releasing the Source code and instructions to interface an ESP8266 module with run basic to allow for input and output to the module connected to a wifi network.
The project consists of a series of lua scripts that run on the ESP8266 module and a set of functions for RunBasic to interface with the device.
I modeled these functions after an existing project for interfacing an arduino with liberty basic and they will be compatible between both platforms. The only change required is to remove the arduino function library and do a find and replace for "AD." with "ESP." in your source code.
I have only implemented the basic input and output functions. PWM is not yet supported.
To interface with a programmed esp module you will call one of the following functions
In these functions the ip address is
To retrieve the current status of a pin (High or low) use the flowing code:
return.value = ESP.Get(IP.Address$, Pin.Selection)
'Example to print status of pin 4
print
ESP.Get("192.168.1.100, 4)This function returns a 1 or a zero depending on if the pin is pulled high or low and is suitable for being used with a push button or magnetic reed switch.
To set a pins output high or low all you do is use the following code:
return.value = ESP.Set(
IP.Address$
, Pin, Val.To.Send)
'Example to set pin 4 high
print
ESP.Set(
"192.168.1.100
, 4, 1)
This function returns a 1 for success and zero if unsuccessful. This function can be used to turn lights on and off, activate relays and do some other fun things.
The function library is as follows:
To use you must add wget download here to your RB101 folder on the c drive.
Linux users don't have to install wget
function ESP.Get(IP.Address$, Pin.Selection)
ESP.Get = val(wget$("http://";IP.Address$;"/?get&";Pin.Selection))
end function
function ESP.Set(IP.Address$, Pin, Val.To.Send)
ESP.Set = val(wget$("http://";IP.Address$;"/?get&";Pin.Selection;"&";Val.To.Send))
end function
function wget$(page.to.get$)
wget$ = shell$("wget ";chr$(34);page.to.get$;chr$(34);" -q -O -")
end function