HTTP - Set up Server to Get the Ameba Status
AmebaD [AMB21 / AMB22 / AMB23 / BW16] x 1
In this example, we connect Ameba to WiFi and use Ameba as server to send message to connected client.
“File” → “Examples” → “WiFi” → “WiFiWebServer”
In the sample code, modify the highlighted snippet and enter the required information (ssid, password, key index) required to connect to your WiFi network.
Upload the code and press the reset button on Ameba. After connecting to WiFi, Ameba starts to run as server. The IP of the server is shown in the serial monitor, and port is 80.
We connect to the server in a browser, and we can see the data sent from the server.
WiFi.begin()to establish WiFi connection.
To get the information of a WiFi connection:
WiFi.SSID()to get SSID of the current connected network.
WiFi.RSSI()to get the signal strength of the connection.
WiFi.localIP()to get the IP address of Ameba.
WiFiServer server()to create a server that listens on the specified port.
server.begin()to tell the server to begin listening for incoming connections.
server.available()to get a client that is connected to the server and has data available for reading.
client.connected()to check whether or not the client is connected.
client.println()to print data followed by a carriage return and newline.
client.print()to print data to the server that a client is connected to.
client.available()to return the number of bytes available for reading.
client.read()to read the next byte received from the server the client is connected to.
client.stop()to disconnect from the server the client is connected to.