diff --git a/UnoWifiInterface.cpp b/UnoWifiInterface.cpp new file mode 100644 index 0000000..ae5a88e --- /dev/null +++ b/UnoWifiInterface.cpp @@ -0,0 +1,113 @@ +/* + * © 2020,Anthony Williams All rights reserved. + * + * This file is part of DCC-EX/CommandStation-EX + * + * + * This is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * It is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with CommandStation. If not, see . + * + * Uno Wifi Interface added by Anthony Williams + */ +#ifndef UnoWifiInterface_cpp +#define UnoWifiInterface_cpp +#endif + +#include "config.h" +#include "defines.h" // This should be changed to DCCEX.h when possible +#if WIFI_ON == true +#include "UnoWifiInterface.h" +#include "DIAG.h" +#include "CommandDistributor.h" + +UnoWifiInterface * UnoWifiInterface::singleton=NULL; +char ReplyBuffer[] = "acknowledged"; +/** + * @brief Setup Ethernet Connection + * + */ +void UnoWifiInterface::setup() +{ + singleton=new UnoWifiInterface(); + if (!singleton->connected) singleton=NULL; +}; + + +/** + * @brief Aquire IP Address from DHCP and start server + * + * @return true + * @return false + */ +UnoWifiInterface::UnoWifiInterface() +{ + + + DIAG(F("\n+++++ Uno Wifi Setup ")); + if (WiFi.status() == WL_NO_MODULE) { + + DIAG(F("Communication with WiFi module failed!")); + return; + } + + String fv = WiFi.firmwareVersion(); + + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + + DIAG(F("Please upgrade the firmware")); + + } + + + while (status != WL_CONNECTED) { + + DIAG(F("Attempting to connect to SSID: %S", WIFI_SSID)); + + status = WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + + // wait 10 seconds for connection: + + delay(10000); + + } + + DIAG(F("Connected to wifi")); + IPAddress ip = WiFi.localIP(); + DIAG(F("IP Address %S", ip)) + // if you get a connection, report back via serial: + + + #ifdef IP_ADDRESS + + #else + + #endif +} + +/** + * @brief Main loop for the EthernetInterface + * + */ +void UnoWifiInterface::loop() +{ + if (!singleton) return; + singleton->loop2(); + +} + + void UnoWifiInterface::loop2() +{ + +} + +#endif \ No newline at end of file diff --git a/UnoWifiInterface.h b/UnoWifiInterface.h new file mode 100644 index 0000000..db2472a --- /dev/null +++ b/UnoWifiInterface.h @@ -0,0 +1,48 @@ +/* + * © 2020,Anthony Williams All rights reserved. + * + * This file is part of DCC-EX/CommandStation-EX + * + * + * This is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * It is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with CommandStation. If not, see . + * + * Uno Wifi Interface added by Anthony Williams + */ +#ifndef UnoWifiInterface_h +#define UnoWifiInterface_h +#endif + +#include +#include +#include "DCCEXParser.h" + +#define MAX_WIFI_BUFFER 512 + +class UnoWifiInterface { + public: + + static void setup(); + static void loop(); + + private: + static UnoWifiInterface * singleton; + bool connected; + UnoWifiInterface(); + void loop2(); + WifiServer * server; + WifiClient clients[MAX_SOCK_NUM]; // accept up to MAX_SOCK_NUM client connections at the same time; This depends on the chipset used on the Shield + uint8_t buffer[MAX_WIFI_BUFFER+1]; // buffer used by TCP for the recv + + +} \ No newline at end of file diff --git a/defines.h b/defines.h index 6db42e1..2234761 100644 --- a/defines.h +++ b/defines.h @@ -23,7 +23,7 @@ // WIFI_ON: All prereqs for running with WIFI are met // -#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_SAMD_ZERO)) +#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_AVR_UNO_WIFI_REV2)) #define WIFI_ON true #else #define WIFI_ON false