mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-06-30 19:15:24 +02:00
more to UnoWifiInterface
This commit is contained in:
parent
0ab483b7d2
commit
98fbf7748b
113
UnoWifiInterface.cpp
Normal file
113
UnoWifiInterface.cpp
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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
|
48
UnoWifiInterface.h
Normal file
48
UnoWifiInterface.h
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Uno Wifi Interface added by Anthony Williams
|
||||
*/
|
||||
#ifndef UnoWifiInterface_h
|
||||
#define UnoWifiInterface_h
|
||||
#endif
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
#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
|
||||
|
||||
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user