ESP8266 BASIC Language Reference
Hardware Basics (Node MCU Board)
WPRINT with htmlvar() function:
Function inherited from the parser (c++ style)
Hardware Basics (Node MCU Board)
ESP-01 BOARD
BASE COMMANDS (Basic Core)
IF .. THEN:
The if then command will compare 2 values or variables.
To check if strings are equal to each other use ‘==’, for numbers use ‘=’.
if {var or value} {=, ==,>,<,<>,>=,<=}, {var or value} then {statement to be executed if true} {else} {Statement if false}
LET:
Let will perform math or string operations on a set of values or variables and place the result into a variable.
To add strings together you must use the ‘&’ symbol instead of the ‘+’
Can also be used to evaluate logic operations like in the if then statement. If the result is true it will return a -1 otherwise a 0
let {Result var} = {value or var} {operator *,/,+,-,^,&} {value or var}
let {Result var} = {value or var} {=, ==,>,<,<>,<=,>=} {value or var}
Can also be used without the let statement
bla = 5 + 5
Comparison Operators: | Math Operators: |
= Equal for numbers == Equal for strings > More than < less than <> Not Equal >= more than or equal <= less than or equal | + Add (Numbers Only) - Subtract * Multiply / Divide ^ To the power of & Add (Text) % Modulo |
Logic Operators: | Boolean Operators: |
And boolean ‘and’ (ex. If a=10 and b=20 then ..) Or boolean ‘or’ (ex. If a=10 or b=20 then ..) Xor boolean ‘xor’ (ex. If a=10 xor b=20 then ..) Not boolean ‘not’ (ex. If not (a=10) then ..) Any combination of these operators is allowed. (ex. If (a=10 or b=20) and c=30 then | And boolean ‘and’ (ex. a = b and c) Or boolean ‘or’ (ex. A = a or 16) Xor boolean ‘xor’ (ex. A = b xor 255) Not boolean ‘not’ (ex. A = not 15 ) << shift left (ex. A = b << 4) >> shift right (ex. A = b >> 8) |
DIM:
Will dimension an array. Arrays dimensioned with out the $ will be defined as numeric. Arrays defined with a $ will be defined as string. Can be used just like other variables. Can not be used for gui widgets.
dim araynumeric( {variable or numeric value} )
dim arraystring$( {variable or numeric value} )
UNDIM:
Will release memory used by an array
undim arraystring$
GOTO:
Will jump to the branch label of your choice
goto {label}
GOSUB AND RETURN:
Will jump to the branch label of your choice and allow you to return to the location you call the gosub from and continue executing code after the return command is executed. The gosub command has a stack of 255 return points so it is possible to gosub from inside a gosub.
gosub {label}
return
FOR ... NEXT loops:
A for ... next loop will loop x number of times.
For x = 1 to 5;
Print x;
Next x
BRANCH LABELS:
A branch label allows you to jump from one part of the program to another. It can be a single string of characters with no spaces.
{label} (branch labels like in qbasic. No colon required)
PRINT:
Will output text or a variable to the serial interface and the browser with a new line.
print {value or var}
SERIALPRINT:
Will output text or a variable to the serial interface only. No new line or added.
serialprint {value or var}
SERIALPRINTLN:
Will output text or a variable to the serial interface only. Will terminate with a new line.
serialprintln {value or var}
BAUDRATE:
Will set the baudrate for serial communications.
baudrate {value or var}
INPUT:
Will request input via serial from the user and place it into a variable. Variable doesn’t needs to be declared prior to request.
input {optional string or var to display in prompt} {value or var}
SERIALFLUSH:
Will clear the serial input buffer. Discards all characters stored in the buffer.
serialflush
SERIALTIMEOUT:
Will cause the input command to return whatever is in the serial buffer even if there is no CR LF. Specifying a value of 0 will disable the serial timeout. Any non-zero value will be the number of milliseconds it will wait before timing out on an input command.
serialtimeout {value or var}
SERIAL PORT 2:
The serial port 2 is also available but only for TX (output only) as the RX pin is s occupied for flash chip connection.
The TX pin for the Serial PORT 2 is the GPIO2
The commands available for the serial port 2 are :
SERIAL2BEGIN:
Open the serial port 2 with the defined baudrate
serial2begin {baudrate}
Example : serial2begin 115200
SERIAL2PRINT:
Will output text or a variable to the serial 2 interface only. No new line or added.
serial2print {value or var}
SERIAL2PRINTLN:
Will output text or a variable to the serial 2 interface only. Will terminate with a new line.
serial2println {value or var}
LOAD:
Will load another basic program into memory. Useful for chaining programs together.
Will load another program into memory and start executing it from the beginning.
All variables previously used will stay in memory and be available to the program that is loaded.
Useful for breaking a project up. ex.
LOAD "\myscript.bas" or LOAD "\uploads\myscript.bas"
load {other program name}
Timers And Interrupts
TIMER:
The Timer command will allow you periodically run a branch. The branch must end with the wait command. Setting the timer to 0 will disable it.
To Set timer:
timer {string or var for wait time in milliseconds}, {branch label}
To Disable timer:
timer 0
SLEEP:
Will put device to sleep for a number of seconds. This will save power and allow for extended use on batteries.
Things to note. Sleep mode will cause a full reboot of the device. It will start the device and run the default program from the beginning. It takes 30 seconds before the device starts the default program after reboot.
GPIO16 needs to be tied to RST to wake from Sleep.
sleep {value or var in seconds}
REBOOT:
Will reboot the device upon execution.
reboot
INTERRUPT:
Will execute a specific branch when a pins status changes. The interrupt polling only occurs when the esp is waiting and useful for things like push buttons trigger events. The branch must end with the wait command.
interrupt {pin no} {branch label}
to disable an interrupt specify no branch label.
interrupt {pin no}
SERIALBRANCH:
Defines a branch to be executed when serial input is received.
serialbranch [branchLabel]
Example
serialbranch [serialin]
wait
[serialin]
serialinput zz$
Serialprint “received:”
serialprintln zz$
return
FILE I/O
READ:
The read command allows you to retrieve information persistently stored in the flash memory of the ESP8266 module.
read {string or var for name of data element} {Var to place contents of data element into}
WRITE:
The write command allows you to persistently store a data element in flash memory.
write {string or var for name of data element} {Var or sting to write to data element}
HARDWARE INTERFACE COMMANDS
For i2c functions see here.
PO:
po allows you to set pin on the esp high or low
po {pin no value or var} {value or var 1/0}
alternative as function
io(po,{pin},{value})
PI:
Will place the high or low status of a pin in to the variable chose.
Useful for reading push buttons and other electronic inputs.
pi {pin no} {var to place result 1/0}
alternative as function
io(pi,{pin})
PWO:
pwo allows you to set pin on the esp for PWM output
pwo {pin no value or var} {value or var}
alternative as function
io(pwo,{pin},{value})
PWI:
Will place pwm input status of a pin in to the variable chose.
Useful for reading push buttons and other electronic inputs.
pwi {pin no} {var to place result in}
alternative as function
io(pwi,{pin})
SERVO:
Will set the angle of a servo connected to the the pin.
Angle must be between 0 and 180.
servo {pin no} {value or var 0 to 180}
alternative as function
io(servo,{pin},{value})
AI:
Analog input is only available on the pin marked "ADC" on the ESP-12.
Useful for retrieving input from photo resistors and other devices.
ai {var to place result in}
io(ai)
LASTSTAT:
This will return the last polled status of a pin such as an interrupt and retain the value until it has changed again in another polling event. Also it will allow you to see the last value sent to a pin for servo, pwm or po.
io(laststat,{pin no})
TEMP:
Will retrieve temperature sensor reading from certain 1 wire devices connected to pin 2. See example here
temp {Device ID} {Variable name to place data into}
delay:
Will wait for a number of milliseconds before continuing execution.
Useful for making leds blink
delay {Var or value}
OLED & LCD DISPLAY COMMANDS
For i2c functions see here.
I2C pins are 0 and 2. On NodeMCU boards they are labeled as D3 and D4.
OLEDPRINT:
Will print to the OLED display at specified position. X position for edge of display will differ for some models.
oledprint {String or var} {x position value or var} {y position value or var}
OLEDCLS:
Will clear the screen.
oledcls
OLEDSEND:
Will send a value to the display. This is for sending native commands and requires a byte as a number. Refer to OLED display command documentation from manufactures spec.
oledsend {Value or var}
1602 LCD COMMANDS
LCDPRINT:
Will print to the OLED display at specified position. X position for edge of display will differ for some models.
lcdprint {String or var} {x position value or var} {y position value or var}
LCDCLS:
Will clear the screen.
lcdcls
LCDBL:
Will turn the back light on or off. 1 for on, 0 for off.
lcdbl {value or var}
LCDSEND:
Will send a value to the display. This is for sending native commands and requires a byte as a number. Refer to LCD display command documentation from manufactures spec. MODE: 0=COMMAND, 1=DATA, 2=FOUR_BITS
lcdsend {Value or var to send} {Value or Var for mode}
FUNCTIONS (NEOPIXEL WS2812)
To use NEO Pixel strips you must connect the signal to pin 15, D8 for node mcu boards.
NEO():
Will set the desired pixel led to the color specified with an RGB (Red, Green, Blue) value.
neo({LED NO},{R},{G},{B})
NEOCLS():
Will turn off all the leds on the strip.
neocls()
neostripcolor():
Will set a range of leds to the desired color.
neostripcolor({start pixel},{end pixel},{R},{G},B})
(FUNCTIONS) DHT21
Functions to interface with the dht21 temp/humidity moduel.
DHT.TEMP():
Will return the temperature reading in celsius from the sensor.
dht.temp()
DHT.HUM():
Will return the humidity
dht.hum()
DHT.HEATINDEX():
Compute heat index in Fahrenheit.
dht.heatindex()
WEB INTERFACE COMMANDS
CLS:
Will clear the screen and GUI buffer
cls
WPRINT:
Will print text to the browser. Text will be sent to the browser upon the wait command. Note that there is no new line after it is printed so you must add html to create a new line or horizontal rule.
wprint {value or var}
WPRINT with htmlvar() function:
To place a dynamic variable that will update on each refresh of the page with the current contents of that variable use the htmlvar function.
Each time browser is refreshed the latest contents of the variable are place in the page.
wprint htmlvar({var name})
IMAGE:
Will insert an image into the web page. Image file should be uploaded to device using the file manager.
image {image file name}
JAVASCRIPT:
Will allow you to include javascript files in your page. File must be uploaded to the device using the file manager.
javascript {filename}
CSS:
Will allow you to include css files in your page. File must be uploaded to the device using the file manager.
See the CSS example here.
css {filename}
BUTTON:
Functions like a goto command. Will be sent to the browser on the wait command.
Will goto the branch label when clicked in the browser
button {value or var} {Branch Label}
IMAGEBUTTON:
Functions like a goto command. Will be sent to the browser on the wait command.
Will goto the branch label when clicked in the browser. The image file must be uploaded to the device using the file manager.
imagebutton {image file name} {Branch Label}
TEXTBOX:
The text inside the text entry filled will be whatever is in the variable.
Will be displayed in the browser on the wait command
textbox {var name}
PASSWORDBOX:
The text inside the password entry filled will be whatever is in the variable.
Will be displayed in the browser on the wait command
passwordbox {var name}
SLIDER:
The slider will be created with a maximum and minimum value.
slider {Var name} {min value} {max value}
DROPDOWN:
The selected item will be placed into the variable.
dropdown {Item list separated by commas} {var name}
example
dropdown "One,Two,Three" bla
LISTBOX:
The selected item will be placed into the variable.
listbox {Item list separated by commas} {var name} {Height in items}
example
listbox "One,Two,Three" bla 5
ONLOAD:
Optional branch to be executed any time a page is loaded from the device. This code will be executed before the page is returned but after any branches for buttons. Branch must terminate with wait command.
onload {branch label}
WAIT:
Sends all the accumulated gui commands to the browser.
The browser will display once this command is run
wait
HTMLID():
The html id function will return the randomly generated id for the last gui object created. Useful for javascript interaction capabilities.
htmlid()
WEB MSG HANDLER COMMANDS
Msg handler events will only be handed when there is a request t the url http://device ip/msg is used.
See example /msg-url-usage.html for more information.
MSGBRANCH:
Will set the branch for handling msg input urls. This branch will execute when the url "ESP-IP-address/msg" is accessed.
msgbranch {branch label}
MSGGET:
Will retrieve a url argument and place it in a variable.
msgget {url arg} {variable name}
Example:
Will retrieve the url argument "color" and place it into myColorVar
Use browser to access "ESP-IP-address/msgcolor=blue"
msgget "collor" myColorVar
MSGRETURN:
Will set the text to be returned by the browser. No additional html is provide. Will overwrite previous return text if called more than once. Text will be returned when interpreter encounters the wait command.
msgreturn {variable name or string for return}
SMTP EMAIL COMMANDS
You will need an SMTP server such as http://www.smtp2go.com/
SMTP Server: mail.smtp2go.com
Port: 2525
For sending sms message to phones look up your criers sms gateway.
http://martinfitzpatrick.name/list-of-email-to-sms-gateways/
SETUPEMAIL:
Will configure the email server. Requires the server, port, user name and password.
setupemail {String for server} {Value for port} {String for user name} {String for password}
EMAIL:
Will send an email using the from and to address using the subject and body.
email {String To email} {String From Email} {String Subject} {String Body}
GRAPHICS COMMANDS
Colors are optional. If no color is specified it will default to black
For examples you can look at /graphics-example.html and /graphic-clock-example.html
GRAPHICS
Adds a graphics element to the page
Each parameter can be a variable or a value.
graphics {width} {height}
GCLS:
Will clear the graphics buffer.
gcls
LINE:
Creates a line in the graphic element
Each parameter can be a variable or a value.
line {x1} {y1} {x2} {y2} {color}
CIRCLE:
Creates a circle in the graphic element
Each parameter can be a variable or a value.
circle {x1} {y1} {radius} {color}
ELLIPSE:
Creates a ellipse in the graphic element
Each parameter can be a variable or a value.
ellipse {x1} {y1} {radiusX} {radiusY} {color}
RECT:
Creates a rectangle in the graphic element
Each parameter can be a variable or a value.
rect {x1} {y1} {radiusX} {radiusY} {color}
Color palette
0 = Black
1 = Navy
2 = Green
3 = Teal
4 = Maroon
5 = Purple
6 = Olive
7 = Silver
8 = Gray
9 = Blue
10 = Lime
11 = Aqua
12 = Red
13 = Fuchsia
14 = Yellow
15 = White
WIFI COMMANDS
CONNECT:
Will connect you to the wifi network using the ssid and password. Optionally you may specify the ip ADDRESS, Gateway and subnet mask for a static ip.
connect {Var or String for SSID} {Var Or String for password}
Static ip:
connect {Var or String for SSID} {Var Or String for password} {ip var or sting} {gateway var or sting} {netmask var or sting}
AP:
Will create an access point with the name and password you specify.
If the password is not specified it will be an open network.
ap {Var or String for SSID} {Var Or String for password}
WIFIOFF:
Will turn off all networking for sta and ap mode. The WiFioff command can be called in order to disable all networking. The ap or connect command if run after WiFioff will activate that particular WiFi mode. You can turn them both back on at any point with each of these commands.
wifioff
WIFI.SCAN():
Will return the number of available wifi networks. See an example here.
wifi.scan()
WIFI.SSID():
Returns the network name for the selected network. See an example here.
Must run a wifi.scan() first.
wifi.ssid({Var for network number})
WIFI.RSSI():
Returns the signal strength for the selected network. See an example here.
Must run a wifi.scan() first.
wifi.rssi({Var for network number})
FUNCTIONS (THINGSPEAK API)
To get started with thing speak visit there web site at https://thingspeak.com/
You need to have an account and channel/api key all set up.
These functions will only work if the esp is connected to a network with the internet.
SENDTS:
Will post the fields contents to the thingspeak service. Must use the thingspeak key and field number.
SENDTS({KEY},{FILED NUMBER},{FIELD CONTENTS})
READTS:
Will return the last value published for the desired field. Must use the thingspeak key, channel id and field number.
readts({KEY},{CHANNEL ID},{FIELD NUMBER})
FUNCTIONS String
Functions can be called in place of variables and will typically return value.
Function names are not case sensitive. ie. LeN() and len() are both valid
len():
Will return the length of the string
len({string or var name})
instr():
Will return location of a sub string within a string.
instr({string or var name},{string or var name to locate})
mid():
Will return the string from the start position to the end position inside of the input string.
mid({string or var name},{Start position},{number of characters})
left():
Will return a string that contains a specified number of characters from the left side of a string.
left({string or var name},{length})
right():
Will return a string containing a specified number of characters from the right side of a string.
right({string or var name},{length})
str():
Will return the returns a string representation of a number
str({number or var name})
replace():
Will return a string after replacing the search text with the replacement text.
replace({string or var name},{string to search for},{replacement for string})
chr():
Will return a character for the given number.
chr({string or var name})
asc():
Will return a number for the first character in a string.
asc({string or var name})
upper():
Will return the supplied string in UPPERCASE.
upper({string or var name})
lower():
Will return the supplied string in lowercase.
lower({string or var name})
id():
Will return the unique id of the chip.
id()
word():
This function returns the nth word in the string, string variable or string expression.
The string delimiter is optional. When it is not used, the space character is the delimiter.
word( {original string}, {number}, {optional delimiter. Default is space} )
Ex.
word(“The quick brown fox jumped over the lazy dog”, 5) will return “jumped”
json():
Will parse a json string for the articular named data element within it.
json({string or var name for data to be parsed},{string or var name for key name in data})
The key can have the following syntax :
“Key.subkey.innerkey…..” . Array can also be included such as “weather[5].description”
Example with OpenWeatherAPI :
let apid = “xxxxx” ‘ place your APP_ID here
let query = "api.openweathermap.org/data/2.5/weather?&units=metric&q=Miami,us&appid="; & appid
let ret = wget(query)
serialprintln ret
let desc = json(ret,"weather.description")
let temp = json(ret,"main.temp")
let press = json(ret,"main.pressure")
let humid = json(ret,"main.humidity")
ReadOpenWeather():
Will parse a json string coming from an OpenWeatherAPI forecast request.
At this kind of request generates a big amount of data, this function parse directly from the stream minimising the use of the RAM memory.
It permit to extract, from the stream, the particular item required; the extracted data can then be parsed by the function json().
The index_number can be 0, in that case the function will return the json root
readopenweather({String or var name for url} , {index_number})
Example with OpenWeatherAPI forecast :
let apid = “xxxxx” ‘ place your APP_ID here
‘This query represent a daily forecast for Miami, Florida; each item represent a day
let query = "api.openweathermap.org/data/2.5/forecast/daily?&units=metric&q=Miami,us&appid="; & appid
let ret = readopenweather(query,1) ' the 1 means the first item of the list - 0 means the root
let temp_min = json(ret,"temp.min")
let temp_max = json(ret,"temp.max")
let tim = json(ret,"dt")
let tim = unixtime(tim)
print "Date :" & tim & " T min " & temp_min & " T max " & temp_max
FUNCTIONS (Numeric)
Search
FUNCTIONS
Functions can be called in place of variables and will typically return value.
Function names are not case sensitive. ie. LeN() and len() are both valid
Math Functions:
sqr():
Will return the square root.
sqr({value or var name})
sin():
Will return the sine of an angle.
sin({value or var name})
cos():
Will return the cosine of an angle.
cos({value or var name})
tan():
Will return the tangent of an angle.
tan({value or var name})
log():
Will return the log of the provided value.
log({value or var name})
rnd():
Will return a random number up to the value set.
rnd({value or var name})
millis():
Will return number of milliseconds since boot time.
millis()
int():
Will return an integer value.
int({string or var name})
val():
Will return a value from a string.
int({string or var name})
oct():
Will return the oct value of an integer.
oct({string or var name})
hex():
Will return the hex value of an integer.
hex({string or var name})
hextoint():
Will return an integer value from an hex value
hextoint({string or var name})
ramfree():
Will return the amount of ram free in bytes.
ramfree()
flashfree():
Will return the amount of flash free in bytes. This is only applicable to flash designated for the file system.
flashfree()
Function inherited from the parser (c++ style)
pow(x, y ):
Returns x raised to the power of y.
exp(x):
Returns the value of e raised to the xth power.
asin(x):
Returns the arc sine of x in radians.
acos(x):
Returns the arc cosine of x in radians.
atan(x):
Returns the arc tangent of x in radians.
atan2(x, y):
Returns the arc tangent in radians of y/x based on the signs of both values to determine the correct quadrant.
abs(x):
Returns the absolute value of x converted to integer.
fabs(x)
Returns the absolute value of x.
floor(x):
Returns the largest integer value less than or equal to x.
ceil(x):
Returns the smallest integer value greater than or equal to x.
round(x):
Return the integral value nearest to x rounding halfway cases away from zero, regardless of the current rounding direction.
FUNCTIONS (Time&Date)
FUNCTIONS
Functions can be called in place of variables and will typically return value.
Function names are not case sensitive. ie. LeN() and len() are both valid
NOTE: No spaces should be used inside a function. Only commas if there are multiple values to be parsed.
let bla = len("hello world") is ok
let ble = len( "hello world" ) is not ok.
Time and date functions:
time():
Will return the date and time as a string. You can optionally specify the format you want it back in.
Options: month, day, hour, min, sec, year, dow (Day of the week, ex. fri)
time({Optional specification of format})
with an option.
time("year")
time(“year-month-day”) will return “2016-Apr-10”
unixtime():
Permit to convert from a date/time in unix format (a number) to text.
Will return the date and time as a string. You can optionally specify the format you want it back in.
Options: month, date, hour, min, sec, year, dow (Day of the week, ex. fri)
unixtime({datenumber} , {Optional specification of format})
with an option.
unixtime(1459681200, "year")
timesetup():
Will set up the time time zone and daylight savings attribute.
timesetup({number or var for time zone},{number or var for dst})
FUNCTIONS (Web Related)
Search
FUNCTIONS
Functions can be called in place of variables and will typically return value.
Function names are not case sensitive. ie. LeN() and len() are both valid
NOTE: No spaces should be used inside a function. Only commas if there are multiple values to be parsed.
let bla = len("hello world") is ok
let ble = len( "hello world" ) is not ok.
Internet functions:
wget():
Will fetch the html contents of a web page and return it as a string.
Do not put "http://" in front of the url. Defaults to port 80 if none is specified.
wget({String or var name for url},{Optional port number})
ip():
Will return the units ip address as a string.
ip()
FUNCTIONS I2C
Functions can be called in place of variables and will typically return value.
Function names are not case sensitive. ie. LeN() and len() are both valid
NOTE: No spaces should be used inside a function. Only commas if there are multiple values to be parsed.
let bla = len("hello world") is ok
let ble = len( "hello world" ) is not ok.
i2c functions:
For more information on usage look at this example.
i2c.begin():
Will begin transmission to the I2C device with desired address.
i2c.begin({value or var for device address})
i2c.write():
Will write a single value (1 character) to the i2c device.
i2c.write({value or var for data})
i2c.end():
Will terminate the i2c contamination with a particular device.
i2c.end()
i2c.requestfrom():
Will request a quantity of bytes from device.
i2c.requestfrom({value or var for device id},{value or var for number of bytes to request})
i2c.available():
Returns the number of bytes available for retrieval with i2c.read().
i2c.available()
i2c.read():
Will return a single character as an integer. Character returned will be next out of buffer.
i2c.read()
FUNCTIONS UDP
Udpbegin:
Starts an UDP server listening on the port specified.
udpbegin {localport}
localport is a number (ex: 1234)
Example: udpbegin 4300
Udpstop:
Stop the UDP server
udpstop
Works for UdpBegin and UdpBeginMulticast
UdpbeginMultiCast:
Starts an UDP server multicast listening at the address and the port specified.
udpbeginmulticast {multicast_ip}, {localport}
The multicast IP shall be in the range 224.0.0.0 to 239.255.255.255
Example : udpbeginmulticast “224.0.0.67”, 4567
Udpwrite:
Write a string toward a remote IP and port
udpwrite {ip_address}, {port}, {message}
ip_address is a string (ex: “192.168.1.123”)
message is a string (ex: “This is a valid message”)
port is a number (ex: 5000)
Example: udpwrite “192.168.1.12”, 3000, “Message OK”
UdpwriteMultiCast:
Write a string toward a multicast IP and port
udpwritemulticast {ip_address}, {port}, {message}
ip_address is a string (ex: “224.0.0.50”)
message is a string (ex: “This is a valid message”)
port is a number (ex: 6000)
Example: udpwritemulticast “224.0.0.55”, 3100, “Message NOT delivered!”
UdpReply:
Send an UDP message back to the original transmitter.
Permit to answer directly without specify the IP and port
udpreply {message}
message is a string (ex: “This is a valid message”)
Example: udpreply “Message received”
UdpRead():
Read an UDP message received.
To works, the UDP server needs to be open (commands UdpBegin or UdpBeginMultiCast)
udpread()
Example: let rec = udpread()
UdpRemote():
Read the IP address and the port of the message received
To works, the UDP server needs to be open (commands UdpBegin or UdpBeginMultiCast)
udpremote()
Example: let rem = udpremote()
The result will be in the form of IP:port; example (192.200.150.7:4568)
UdpBranch:
Define a branch label defining the place where the program will continue as soon as an UDP message is received. As soon as the return command is found, the program will continue from the interrupted point.
To works, the UDP server needs to be open (commands UdpBegin or UdpBeginMultiCast)
udpBranch {label}
Example:
udpbegin 4567
udpbranch [udp.received]
wait
[udp.received]
let rec = udpread()
let rem = udpremote()
Serialprint “Message received “ & rec & “ from “ & rem
udpreply “OK”
return
SPECIFICITY OF THE NEW PARSER
String Literals : it’s possible to use the “ or the | as string literals;
This permits to include the “ or | inside a string; example
A = |this is a “string”|
B = “this is a |string|”
Comparison operators for string and numbers:
The ‘=’ or ‘==’ gives the same result for string and numbers
The string can now be compared also for >, <, etc.
Boolan binary operators
The classic “basic” binary operators are available :
and, or, xor, not
Example: print 255 and 15; let a = 255 xor 15; let b = not 15; let c = a or b
Shift operators
The shift left ‘<<’ and shift right ‘>>’ operators are available.
Example: print 15 << 3; let c = a >> 4
Modulo Operator (%)
The modulo operator ‘%’ is available
Example: print 10 % 3
Boolean operators in ‘if’
All the boolean operators can be used in the ‘if’ command :
If a = b and c<>d then …..
All the comparisons can be used into expressions. If the result is true, the value will be -1, 0 is false
Example let a = 5 <> 3 ⇒ -1 print 5*3 = 8 ⇒ -1 print 5-4 = 2 ⇒ 0
Spaces are don’t care :
A = 5 + 3 is the same as a=5+3