#include "secrets.hpp" #include "wifi_module.hpp" #include #include #include constexpr auto BAUDRATE = 9600U; constexpr auto NETWORK_MODULE_RX_PIN = 3; constexpr auto NETWORK_MODULE_TX_PIN = 2; auto wifi_module = WiFiModule(NETWORK_MODULE_RX_PIN, NETWORK_MODULE_TX_PIN); void setup() { Serial.begin(BAUDRATE); pinMode(NETWORK_MODULE_RX_PIN, INPUT); pinMode(NETWORK_MODULE_TX_PIN, OUTPUT); wifi_module.begin(BAUDRATE); wifi_module.reset(); delay(1000); auto wifi_module_connected = wifi_module.test(); Serial.print("Wifi module connected: "); Serial.println(wifi_module_connected ? "Yes" : "No"); if (!wifi_module_connected) { while (true) { } } wifi_module.set_echo_enabled(false); delay(1000); const auto wifi_connect_success = wifi_module.connect(WIFI_SSID, WIFI_PASSWORD); if (wifi_connect_success) { Serial.print("Connected to wifi network '"); Serial.print(WIFI_SSID); Serial.println("' successfully"); } else { Serial.print("Failed to connect to wifi network '"); Serial.print(WIFI_SSID); Serial.println("'"); } wifi_module.set_wifi_mode(WifiMode::Station); delay(3000); char local_ip[MAX_NETWORK_MODULE_RESPONSE_LENGTH] = ""; Serial.print("IP address: "); Serial.println(wifi_module.get_local_ip(local_ip)); wifi_module.set_multiple_connections_enabled(true); delay(1000); wifi_module.create_tcp_server(80U); } void loop() { if (wifi_module.has_incoming_request()) { char raw_request[200] = ""; const auto connection_id = wifi_module.read_incoming_request(raw_request); Serial.print("Connection ID: "); Serial.println(connection_id); Serial.print("\nRaw request: "); Serial.println(raw_request); wifi_module.send(connection_id, "lmao!"); wifi_module.close_connection(connection_id); delay(1000); } }