switch from rf24 to espnow
This commit is contained in:
+38
-3
@@ -59,6 +59,8 @@ bool wifiIsActive;
|
||||
void i2cScanner(void);
|
||||
void makeMenu(void);
|
||||
void restart(void);
|
||||
void recieveCallback (const uint8_t * mac, const uint8_t *incomingData, int len);
|
||||
void sendCallback (const uint8_t *mac_addr, esp_now_send_status_t status);
|
||||
|
||||
|
||||
void setup() {
|
||||
@@ -67,11 +69,15 @@ void setup() {
|
||||
DebugTimes setupTime;
|
||||
char wifiIndicator = 'X';
|
||||
|
||||
WiFi.mode(WIFI_MODE_STA);
|
||||
Serial.print("MAC Address: ");
|
||||
Serial.println(WiFi.macAddress());
|
||||
|
||||
spiPort = new SPIClass(HSPI);
|
||||
spiPort->begin(UBLOX_GNSS_SPI_SCK, UBLOX_GNSS_SPI_CIPO, UBLOX_GNSS_SPI_COPI, UBLOX_GNSS_SPI_CS);
|
||||
|
||||
mainBattery = new Battery(35, 692000, 218500);
|
||||
controlPad = new ControlPad(spiPort, RF24_CE_PIN, RF24_CSN_PIN);
|
||||
controlPad = new ControlPad();
|
||||
controlPad->setMenuControl(main_m);
|
||||
|
||||
Wire.begin(21, 19);
|
||||
@@ -94,11 +100,12 @@ void setup() {
|
||||
} else
|
||||
outputBuf = new OutputBuf();
|
||||
wifiIndicator = '-';
|
||||
} else {
|
||||
} else
|
||||
outputBuf = new OutputBuf();
|
||||
}
|
||||
std::cout.rdbuf(outputBuf);
|
||||
|
||||
Network::connectEspNow(recieveCallback, sendCallback);
|
||||
|
||||
std::cout << "Welcome to Kleiax-Rover" << std::endl;
|
||||
std::cout << "All actions from the main program run on Core -> " << xPortGetCoreID() << std::endl;
|
||||
|
||||
@@ -118,6 +125,23 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static uint32_t lastMillis = 0;
|
||||
if (millis() - lastMillis > 5000) {
|
||||
lastMillis = millis();
|
||||
char blub[] = {"Du dumme Bla"};
|
||||
esp_err_t result = esp_now_send(Network::getBroadcastAddress(), (uint8_t *) blub, sizeof(blub));
|
||||
|
||||
if (result == ESP_OK) {
|
||||
Serial.println("Sent with success");
|
||||
}
|
||||
else {
|
||||
Serial.println("Error sending the data");
|
||||
}
|
||||
// debugMqtt->sendMsg(Loglevel::info, "Alive");
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (wifiIsActive) {
|
||||
DebugTimes wifiTime;
|
||||
Network::checkWiFi();
|
||||
@@ -260,3 +284,14 @@ void restart(void) {
|
||||
lcdWrapper->print("Rebooting ...");
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
void recieveCallback (const uint8_t * mac, const uint8_t *incomingData, int len) {
|
||||
if (len != sizeof(ControlPadInput))
|
||||
return;
|
||||
controlPad->insertData(incomingData);
|
||||
}
|
||||
|
||||
void sendCallback (const uint8_t *mac_addr, esp_now_send_status_t status) {
|
||||
if (status != ESP_NOW_SEND_SUCCESS)
|
||||
std::cout << "sendCallback - Delivery Fail" << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user