|
ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
|
WiFi interface for the esp32. More...
Data Structures | |
| struct | ControllerWiFiResponse |
| WiFi response. More... | |
Enumerations | |
| enum | ControllerWiFiStatus { CONTROLLER_WIFI_NO_SHIELD = 255 , CONTROLLER_WIFI_IDLE_STATUS = 0 , CONTROLLER_WIFI_NO_SSID_AVAIL , CONTROLLER_WIFI_SCAN_COMPLETED , CONTROLLER_WIFI_CONNECTED , CONTROLLER_WIFI_CONNECT_FAILED , CONTROLLER_WIFI_CONNECTION_LOST , CONTROLLER_WIFI_DISCONNECTED } |
| WiFi status. More... | |
Functions | |
| bool | ControllerWiFiConnect (const char *ssid, const char *passwd) |
| Initialize WiFi settings on the esp32. | |
| bool | ControllerWiFiDisconnect (void) |
| Disconnects from the WiFi network. | |
| ControllerWiFiStatus | ControllerWiFiCheckWiFi (void) |
| Checks the current status of WiFi. | |
| bool | ControllerWiFiNtpSync (void) |
| Triggers a NTP sync with the server. | |
| uint32_t | ControllerWiFiTime (void) |
| Get the current time from the NTP server. | |
| bool | ControllerWiFiCheckApi (const char *url) |
| Queries the API endpoint to check if it is reachable. | |
| bool | ControllerWiFiPost (const uint8_t *data, size_t data_len) |
| Post data to the configured endpoint. | |
| ControllerWiFiResponse | ControllerWiFiCheckRequest (void) |
| Checks the status of the most recent HTTP request. | |
| bool | ControllerWiFiHost (const char *ssid, const char *passwd) |
| Sets the esp32 as a WiFi access point. | |
| bool | ControllerWiFiStopHost (void) |
| Stops the esp32 from acting as a WiFi access point. | |
| void | ControllerWiFiHostInfo (char *ssid, char *ip, char *mac, uint8_t *clients) |
| Gets information about the current access point. | |
WiFi interface for the esp32.
The WiFiCommand message is used to control the WiFi hardware on the esp32 module. There are two types: (1) CONNECT which is used to connect to the WiFi network and (2) POST which sends data to an API endpoint.
The return code (rc) message serves dual purpose based on the type and direction of communication. For the CONNECT, the return code is used to send a WiFi enum directly from Arduino WiFi.status(). See this file for possible values. For POST the return code is used to store the HTTP response code from the POST request. See HTTP status code for possible values.
The software flow for WiFi is as follows:
| enum ControllerWiFiStatus |
WiFi status.
The enum is copied from the Arduino WiFi library. See the following for the definitions: https://github.com/arduino-libraries/WiFi/blob/e0e655793d73bfe5c8616bf753c3662dcdf98ad9/src/utility/wl_definitions.h#L59
The meaning of these can be ambiguous. See the following forum for the sequence of status during connect and disconnect events: https://forum.arduino.cc/t/serial-println-wifi-status-codes-meaning/486265/5
| bool ControllerWiFiCheckApi | ( | const char * | url | ) |
Queries the API endpoint to check if it is reachable.
Get the http code and response with
| url | API endpoint url (limited to 256 characters) |
| port | API endpoint port |
Definition at line 104 of file wifi.c.
References CONTROLLER_SUCCESS, and WiFiCommandTransaction().
Referenced by Check().
| ControllerWiFiResponse ControllerWiFiCheckRequest | ( | void | ) |
Checks the status of the most recent HTTP request.
A http_code of 0 indicates that the request was not sent and possibly an error with the WiFi connection.
This function MUST be called immediately after a HTTP request command. Currently unverified how arduino code handles http requests but could cause issues with the server timing out before the esp32 reads the bytes.
Definition at line 135 of file wifi.c.
References ControllerWiFiResponse::bytes, ControllerWiFiResponse::http_code, ControllerWiFiResponse::size, and WiFiCommandTransaction().
| ControllerWiFiStatus ControllerWiFiCheckWiFi | ( | void | ) |
Checks the current status of WiFi.
Definition at line 69 of file wifi.c.
References WiFiCommandTransaction().
Referenced by Connect(), and Disconnect().
| bool ControllerWiFiConnect | ( | const char * | ssid, |
| const char * | passwd | ||
| ) |
Initialize WiFi settings on the esp32.
Connect to a WiFi network with the given SSID and password. This function should be used in a polling configuration to continually check if the esp32 has connected to the WiFi network. The first call initializes the connection and subsequent calls check the connection status.
| ssid | WiFi SSID |
| passwd | WiFi Password |
Definition at line 40 of file wifi.c.
References CONTROLLER_SUCCESS, ssid, and WiFiCommandTransaction().
Referenced by Connect().
| bool ControllerWiFiDisconnect | ( | void | ) |
Disconnects from the WiFi network.
Returns immediately after signal is sent to the esp32 to disconnect from the current WiFi network.
Definition at line 56 of file wifi.c.
References CONTROLLER_SUCCESS, and WiFiCommandTransaction().
Referenced by Disconnect().
| bool ControllerWiFiHost | ( | const char * | ssid, |
| const char * | passwd | ||
| ) |
Sets the esp32 as a WiFi access point.
This function configures the esp32 to act as a WiFi access point with the given SSID and password. If the password is an empty string, the access point will be open (no password).
| ssid | SSID for the access point |
| passwd | Password for the access point (empty for open) |
Definition at line 156 of file wifi.c.
References CONTROLLER_SUCCESS, ssid, and WiFiCommandTransaction().
Referenced by test_ControllerWiFiHost(), and UserConfigStart().
| void ControllerWiFiHostInfo | ( | char * | ssid, |
| char * | ip, | ||
| char * | mac, | ||
| uint8_t * | clients | ||
| ) |
Gets information about the current access point.
Copies the SSID, IP address, and MAC address of the access point into the provided buffers. The buffers must be large enough to hold the respective strings. SSID should be at least 32 bytes, IP should be at least 16 bytes, and MAC should be at least 18 bytes.
If the pointers are NULL, the corresponding information will not be copied.
| ssid | Buffer to store the SSID of the access point. |
| ip | Buffer to store the IP address of the access point. |
| mac | Buffer to store the MAC address of the access point. |
| clients | Pointer to store the number of connected clients. |
Definition at line 186 of file wifi.c.
References ssid, and WiFiCommandTransaction().
Referenced by test_ControllerWiFiHostInfo(), UserConfigStart(), and UserConfigStopCallback().
| bool ControllerWiFiNtpSync | ( | void | ) |
Triggers a NTP sync with the server.
Definition at line 80 of file wifi.c.
References CONTROLLER_SUCCESS, and WiFiCommandTransaction().
Referenced by TimeSync().
| bool ControllerWiFiPost | ( | const uint8_t * | data, |
| size_t | data_len | ||
| ) |
Post data to the configured endpoint.
Get the http code and response with
| data | Binary data |
| data_len | Length of data |
| resp | Buffer to store response |
| resp_len | Pointer to store length of resp |
Definition at line 118 of file wifi.c.
References CONTROLLER_SUCCESS, data, data_len, and WiFiCommandTransaction().
Referenced by Upload().
| bool ControllerWiFiStopHost | ( | void | ) |
Stops the esp32 from acting as a WiFi access point.
Does not turn off the WiFi module on the esp32.
Definition at line 173 of file wifi.c.
References CONTROLLER_SUCCESS, and WiFiCommandTransaction().
Referenced by test_ControllerWiFiStopHost(), and UserConfigStopCallback().
| uint32_t ControllerWiFiTime | ( | void | ) |
Get the current time from the NTP server.
Errors are indicated by a 0 return value.
Definition at line 93 of file wifi.c.
References WiFiCommandTransaction().
Referenced by TimeSync().