network is now a component
This commit is contained in:
+31
-32
@@ -29,6 +29,7 @@
|
||||
#include "LcdWrapper.h"
|
||||
#include "moveControl.h"
|
||||
#include "network.h"
|
||||
#include "networkConfig.h"
|
||||
#include "debugMqtt.h"
|
||||
#include "battery.h"
|
||||
#include "sensorData.h"
|
||||
@@ -45,10 +46,10 @@
|
||||
#include "SpecialMenus/Systeminformation/menuSysteminformation.h"
|
||||
#include "SpecialMenus/PID/menuPidSettings.h"
|
||||
#include "SpecialMenus/Route/menuRoute.h"
|
||||
#include "SpecialMenus/GPS/menuGPS.h"
|
||||
#include "SpecialMenus/SensorData/menuSensorData.h"
|
||||
|
||||
MoveControl moveController;
|
||||
Network* network;
|
||||
DriveManager* driveManager;
|
||||
Menu* main_m;
|
||||
LiquidCrystal_I2C* lcd;
|
||||
@@ -68,17 +69,13 @@ void restart(void);
|
||||
void receiveCallback (const uint8_t * mac, const uint8_t *incomingData, int len);
|
||||
void sendCallback (const uint8_t *mac_addr, esp_now_send_status_t status);
|
||||
void lcdWrapperCallback (const char data[][LcdWrapper::totalRows], uint8_t lines, uint8_t rows);
|
||||
NetworkAdresses setIPs(void);
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
// DebugTimes::setConsolOutput(true);
|
||||
DebugTimes setupTime;
|
||||
char wifiIndicator = 'X';
|
||||
|
||||
WiFi.mode(WIFI_MODE_STA);
|
||||
Serial.print("MAC Address: ");
|
||||
Serial.println(WiFi.macAddress());
|
||||
|
||||
spiPort = new SPIClass(HSPI);
|
||||
spiPort->begin(PinNumbers::spiSck, PinNumbers::spiCipo, PinNumbers::spiCopi, PinNumbers::gnssSpiCs);
|
||||
@@ -94,25 +91,21 @@ void setup() {
|
||||
lcd->clear();
|
||||
lcd->noBacklight();
|
||||
|
||||
Network::setIps();
|
||||
Network::setupMQTT();
|
||||
wifiIsActive = Network::connectWifi();
|
||||
if (wifiIsActive) {
|
||||
Network::initMQTT();
|
||||
if (Network::checkMQTT()) {
|
||||
DebugMqtt::init(Network::getMqttClient(), Loglevel::debug);
|
||||
std::cout << "Activate additional output via MQTT..." << std::endl;
|
||||
network = new Network(NetworkConfig::ssid, NetworkConfig::password, setIPs());
|
||||
network->activateEspNow(receiveCallback, sendCallback);
|
||||
if (NetworkConfig::mqtt) {
|
||||
if (network->activateMqtt(MqttConfig::user, MqttConfig::password)) {
|
||||
DebugMqtt::init(network->getMqttClient(), Loglevel::debug);
|
||||
debugMqtt = new DebugMqtt("Console");
|
||||
outputBuf = new OutputBuf(debugMqtt);
|
||||
} else
|
||||
outputBuf->activateMqtt(true);
|
||||
} else {
|
||||
outputBuf = new OutputBuf();
|
||||
wifiIndicator = '-';
|
||||
}
|
||||
} else
|
||||
outputBuf = new OutputBuf();
|
||||
std::cout.rdbuf(outputBuf);
|
||||
|
||||
Network::connectEspNow(receiveCallback, sendCallback);
|
||||
|
||||
std::cout << "Welcome to Kleiax-Rover" << std::endl;
|
||||
std::cout << "Project verion: " << VERSION << std::endl;
|
||||
std::cout << "Build timestamp: " << BUILD_TIMESTAMP << std::endl;
|
||||
@@ -121,11 +114,12 @@ void setup() {
|
||||
sensorData = new SensorData();
|
||||
sensorData->enableGnss(spiPort, PinNumbers::gnssSpiCs);
|
||||
sensorData->enableRealCompass();
|
||||
sensorData->enableGyroskop();
|
||||
// sensorData->enableGyroskop();
|
||||
driveManager = new DriveManager(&moveController, sensorData, controlPad->getControlPadDataPtr());
|
||||
|
||||
outputBuf->activateMqtt(true);
|
||||
|
||||
char wifiIndicator = 'X';
|
||||
if (network->isWifiConnected())
|
||||
wifiIndicator = '-';
|
||||
lcd->backlight();
|
||||
lcd->printf("%c Kleiax-Rover %c", wifiIndicator, wifiIndicator);
|
||||
lcd->setCursor(0, 1);
|
||||
@@ -139,16 +133,7 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (wifiIsActive) {
|
||||
DebugTimes wifiTime;
|
||||
Network::checkWiFi();
|
||||
#ifdef MQTT
|
||||
bool err = Network::checkMQTT();
|
||||
if (!err)
|
||||
std::cout << "loop(): checkMQTT returns false" << std::endl;
|
||||
#endif //MQTT
|
||||
wifiTime.stopConsol("WiFi-Time", 10);
|
||||
}
|
||||
network->loop();
|
||||
sensorData->loop();
|
||||
driveManager->loop();
|
||||
controlPad->loop();
|
||||
@@ -297,8 +282,22 @@ void lcdWrapperCallback (const char data[][LcdWrapper::totalRows], uint8_t lines
|
||||
if (!controlPad->isControlPadConnected())
|
||||
return;
|
||||
|
||||
esp_err_t result = esp_now_send(Network::getBroadcastAddress(), (uint8_t *) data, lines * rows);
|
||||
esp_err_t result = esp_now_send(network->getBroadcastAddress(), (uint8_t *) data, lines * rows);
|
||||
|
||||
if (result != ESP_OK)
|
||||
Serial.println("Error sending the data");
|
||||
}
|
||||
|
||||
NetworkAdresses setIPs() {
|
||||
NetworkAdresses adresses;
|
||||
adresses.localIP.fromString(NetworkConfig::ip);
|
||||
adresses.subnet.fromString(NetworkConfig::subnet);
|
||||
adresses.gateway.fromString(NetworkConfig::gateway);
|
||||
adresses.dnsServer.fromString(NetworkConfig::dns);
|
||||
if (NetworkConfig::mqtt) {
|
||||
adresses.mqttServer.fromString(MqttConfig::server);
|
||||
adresses.mqttPort = MqttConfig::port;
|
||||
}
|
||||
|
||||
return adresses;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user