wifi dependency removed
This commit is contained in:
+4
-1
@@ -34,8 +34,11 @@ class Network {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Establish a connection to the WiFi.
|
* @brief Establish a connection to the WiFi.
|
||||||
|
*
|
||||||
|
* @return true Wifi is connected
|
||||||
|
* @return false Timeout
|
||||||
*/
|
*/
|
||||||
static void connectWifi();
|
static bool connectWifi();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set all general settings to connect to a broker.
|
* @brief Set all general settings to connect to a broker.
|
||||||
|
|||||||
+16
-1
@@ -14,7 +14,22 @@
|
|||||||
|
|
||||||
// General config
|
// General config
|
||||||
#define MQTT_TIME_RECONNECT 2500
|
#define MQTT_TIME_RECONNECT 2500
|
||||||
#define HW1
|
|
||||||
|
/**
|
||||||
|
* @brief Wlan connect timeout
|
||||||
|
*
|
||||||
|
* This number multiplied by WLAN_CONNECT_LOOP_TIME is the
|
||||||
|
* timeout in milliseconds.
|
||||||
|
*/
|
||||||
|
#define WLAN_CONNECT_TIMEOUT 20
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Wlan connect loop time
|
||||||
|
*
|
||||||
|
* The time in milliseconds until the next connection attempt.
|
||||||
|
*/
|
||||||
|
#define WLAN_CONNECT_LOOP_TIME 500
|
||||||
|
#define ESP32BROKER
|
||||||
|
|
||||||
|
|
||||||
//Network config ESP32
|
//Network config ESP32
|
||||||
|
|||||||
+33
-8
@@ -18,13 +18,14 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <LiquidCrystal_I2C.h>
|
#include <LiquidCrystal_I2C.h>
|
||||||
|
#include <BluetoothSerial.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "driveModi/driveManager.h"
|
#include "driveModi/driveManager.h"
|
||||||
|
#include "OutputBuf/outputBuf.h"
|
||||||
#include "moveControl.h"
|
#include "moveControl.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "outputBufMqtt.h"
|
|
||||||
#include "debugMqtt.h"
|
#include "debugMqtt.h"
|
||||||
|
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
@@ -40,8 +41,11 @@ MoveControl moveController;
|
|||||||
DriveManager driveManager(&moveController);
|
DriveManager driveManager(&moveController);
|
||||||
Menu* main_m;
|
Menu* main_m;
|
||||||
LiquidCrystal_I2C* lcd;
|
LiquidCrystal_I2C* lcd;
|
||||||
OutputBufMqtt* bufMqtt;
|
OutputBuf* outputBuf;
|
||||||
DebugMqtt* debugMqtt;
|
DebugMqtt* debugMqtt = nullptr;
|
||||||
|
BluetoothSerial* serialBT = nullptr;
|
||||||
|
|
||||||
|
bool wifiIsActive;
|
||||||
|
|
||||||
void callbackControllerAction(void);
|
void callbackControllerAction(void);
|
||||||
void callbackControllerConnect(void);
|
void callbackControllerConnect(void);
|
||||||
@@ -51,17 +55,21 @@ void makeMenu(void);
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
char wifiIndicator = 'X';
|
||||||
|
|
||||||
Network::setIps();
|
Network::setIps();
|
||||||
Network::connectWifi();
|
|
||||||
Network::setupMQTT();
|
Network::setupMQTT();
|
||||||
|
wifiIsActive = Network::connectWifi();
|
||||||
|
if (wifiIsActive) {
|
||||||
Network::checkMQTT();
|
Network::checkMQTT();
|
||||||
DebugMqtt::init(Network::getMqttClient(), Loglevel::debug);
|
DebugMqtt::init(Network::getMqttClient(), Loglevel::debug);
|
||||||
|
|
||||||
std::cout << "Activate additional output via MQTT..." << std::endl;
|
std::cout << "Activate additional output via MQTT..." << std::endl;
|
||||||
debugMqtt = new DebugMqtt("Console");
|
debugMqtt = new DebugMqtt("Console");
|
||||||
bufMqtt = new OutputBufMqtt(debugMqtt);
|
outputBuf = new OutputBuf(debugMqtt);
|
||||||
std::cout.rdbuf(bufMqtt);
|
wifiIndicator = '-';
|
||||||
|
} else
|
||||||
|
outputBuf = new OutputBuf();
|
||||||
|
std::cout.rdbuf(outputBuf);
|
||||||
|
|
||||||
std::cout << "Welcome to Kleiax-Rover" << std::endl;
|
std::cout << "Welcome to Kleiax-Rover" << std::endl;
|
||||||
std::cout << "All actions from the main program run on Core -> " << xPortGetCoreID() << std::endl;
|
std::cout << "All actions from the main program run on Core -> " << xPortGetCoreID() << std::endl;
|
||||||
@@ -69,14 +77,22 @@ void setup() {
|
|||||||
Ps3.attach(callbackControllerAction);
|
Ps3.attach(callbackControllerAction);
|
||||||
Ps3.attachOnConnect(callbackControllerConnect);
|
Ps3.attachOnConnect(callbackControllerConnect);
|
||||||
std::cout << "\nReady to connect a PS3 Controller... \n";
|
std::cout << "\nReady to connect a PS3 Controller... \n";
|
||||||
|
|
||||||
|
// Need to be connected befor an other device connect
|
||||||
Ps3.begin(CONTROLLER_MAC);
|
Ps3.begin(CONTROLLER_MAC);
|
||||||
|
|
||||||
|
std::cout << "Activate additional output via Bluetooth..." << std::endl;
|
||||||
|
serialBT = new BluetoothSerial;
|
||||||
|
serialBT->begin("Kleiax-Rover");
|
||||||
|
outputBuf->setSerialBT(serialBT);
|
||||||
|
outputBuf->activateMqtt(false);
|
||||||
|
|
||||||
Wire.begin(21, 19);
|
Wire.begin(21, 19);
|
||||||
// i2cScanner();
|
// i2cScanner();
|
||||||
lcd = new LiquidCrystal_I2C(0x3F,16,2);
|
lcd = new LiquidCrystal_I2C(0x3F,16,2);
|
||||||
lcd->init();
|
lcd->init();
|
||||||
lcd->backlight();
|
lcd->backlight();
|
||||||
lcd->print("- Kleiax-Rover -");
|
lcd->printf("%c Kleiax-Rover %c", wifiIndicator, wifiIndicator);
|
||||||
lcd->setCursor(0, 1);
|
lcd->setCursor(0, 1);
|
||||||
lcd->print("Press PS-Button");
|
lcd->print("Press PS-Button");
|
||||||
|
|
||||||
@@ -84,9 +100,18 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
if (wifiIsActive) {
|
||||||
Network::checkWiFi();
|
Network::checkWiFi();
|
||||||
Network::checkMQTT();
|
Network::checkMQTT();
|
||||||
|
}
|
||||||
|
|
||||||
driveManager.loop();
|
driveManager.loop();
|
||||||
|
|
||||||
|
// static uint32_t lastMillis = 0;
|
||||||
|
// if (millis() - lastMillis > 2000) {
|
||||||
|
// std::cout << "Is BT-Consol connected: " << serialBT->connected() << std::endl;
|
||||||
|
// lastMillis = millis();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void callbackControllerAction() {
|
void callbackControllerAction() {
|
||||||
|
|||||||
+11
-3
@@ -31,7 +31,7 @@ void Network::setupMQTT() {
|
|||||||
// mqtt_client->setServer(mqtt_server, MQTT_PORT);
|
// mqtt_client->setServer(mqtt_server, MQTT_PORT);
|
||||||
Network::mqtt_client->setServer(MQTT_SERVER, MQTT_PORT);
|
Network::mqtt_client->setServer(MQTT_SERVER, MQTT_PORT);
|
||||||
Network::mqtt_client->setSocketTimeout(1);
|
Network::mqtt_client->setSocketTimeout(1);
|
||||||
Network::connectMQTT();
|
// Network::connectMQTT();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Network::connectMQTT() {
|
bool Network::connectMQTT() {
|
||||||
@@ -52,7 +52,7 @@ bool Network::connectMQTT() {
|
|||||||
}
|
}
|
||||||
return mqtt_client->connected();
|
return mqtt_client->connected();
|
||||||
}
|
}
|
||||||
void Network::connectWifi() {
|
bool Network::connectWifi() {
|
||||||
// Configures static IP address
|
// Configures static IP address
|
||||||
if (!WiFi.config(local_IP, gateway, subnet))
|
if (!WiFi.config(local_IP, gateway, subnet))
|
||||||
std::cout << "STA Failed to configure" << std::endl;
|
std::cout << "STA Failed to configure" << std::endl;
|
||||||
@@ -60,9 +60,16 @@ void Network::connectWifi() {
|
|||||||
// Connect to Wi-Fi network with SSID and password
|
// Connect to Wi-Fi network with SSID and password
|
||||||
std::cout << "Connecting to " << WLAN_SSID << std::endl;
|
std::cout << "Connecting to " << WLAN_SSID << std::endl;
|
||||||
WiFi.begin(WLAN_SSID, WLAN_PASSWORD);
|
WiFi.begin(WLAN_SSID, WLAN_PASSWORD);
|
||||||
|
uint8_t timeout = WLAN_CONNECT_TIMEOUT;
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(500);
|
delay(WLAN_CONNECT_LOOP_TIME);
|
||||||
std::cout << "." << std::flush;
|
std::cout << "." << std::flush;
|
||||||
|
timeout--;
|
||||||
|
if (timeout == 0) {
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << "WiFi NOT connected." << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print local IP address and start web server
|
// Print local IP address and start web server
|
||||||
@@ -70,6 +77,7 @@ void Network::connectWifi() {
|
|||||||
std::cout << "WiFi connected." << std::endl;
|
std::cout << "WiFi connected." << std::endl;
|
||||||
std::cout << "IP address: " << std::endl;
|
std::cout << "IP address: " << std::endl;
|
||||||
std::cout << WLAN_IP << std::endl;
|
std::cout << WLAN_IP << std::endl;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::checkMQTT() {
|
void Network::checkMQTT() {
|
||||||
|
|||||||
Reference in New Issue
Block a user