diff options
author | HampusM <hampus@hampusmat.com> | 2022-05-08 18:55:42 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-05-08 18:55:42 +0200 |
commit | 2809f92eeb8b727e20167fe82e4cb9c3627d4870 (patch) | |
tree | 06a01c862088333aa388e74dfa4381a87568bfc1 /minion/src/gymnasiearbete.cpp | |
parent | 3a11866cb6a8fd46d86cb6e04dc1022344ea8d45 (diff) |
chore: move most files to minion folder
Diffstat (limited to 'minion/src/gymnasiearbete.cpp')
-rw-r--r-- | minion/src/gymnasiearbete.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/minion/src/gymnasiearbete.cpp b/minion/src/gymnasiearbete.cpp new file mode 100644 index 0000000..0e1adb5 --- /dev/null +++ b/minion/src/gymnasiearbete.cpp @@ -0,0 +1,69 @@ +#include "secrets.hpp" +#include "wifi_module.hpp" + +#include <Arduino.h> +#include <SoftwareSerial.h> +#include <string.h> + +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)); +} + +void loop() {} |