-
Notifications
You must be signed in to change notification settings - Fork 33
Peripherals: Networking
Currently, the following network devices are supported:
- Wifi on ESP8266 in station mode
- Wifi on ESP32 in station mode
- Wifi on MKR and RP2040 Arduinos with the WifiNINA library in station mode
- Arduino Ethernet shields with AVR Mega2560 CPUS using the Arduino Ethernet library.
All the network background tasks, yielding, refreshing of DHCP and reconnection are handled by BASIC in the background.
The only protocol supported at the moment is unencrypted and unauthenticated MQTT. Wifi credentials and the MQTT server are compiled into the executable using the information in the file wifisettings.h. They cannot be changed at run time of the BASIC interpreter.
This protocol is mapped to I/o channel 9.
OPEN &9, "iotbasic/data"
opens a a topic for read. AVAIL(9), INPUT &9, GET &9 read data from that topic.
OPEN &9, "iotbasic/data", 1
opens the topic for write. PRINT &9, PUT &9 write data to the topic.
NETSTAT can be a function or a command. As a function it returns the network status. 0 is "not connecected", 1 is "Wifi connected", 3 is "MQTT and Wifi connected". A typical command would be
IF NETSTAT=3 THEN PRINT "Wifi and MQTT online"
IF NETSTAT=1 THEN PRINT "MQTT lost connection"
IF NETSTAT=0 THEN PRINT "No network connection"
As a command, NETSTAT can stop and start the network
- NETSTAT 0 stops the network
- NETSTAT 1 restarts the network
- NETSTAT 2 reconnects MQTT
NETSTAT without an argument prints the network status. This is mostly meant for interactive use.