Made the code ESP32-compatible.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Fabian Schlenz 2019-06-06 12:12:58 +02:00
parent c9dfc908af
commit 560b71425d
4 changed files with 39 additions and 7 deletions

View File

@ -5,7 +5,13 @@
#pragma message "MQTT_ENABLE is false. Skipping MQTT."
#else
#include <ESP8266WiFi.h>
#if defined( ESP8266 )
#include <ESP8266WiFi.h>
#elif defined( ESP32 )
#include <WiFi.h>
#else
#error "Neither ESP32 nor ESP8266 set..."
#endif
#include <PubSubClient.h>
#include "EffectEntry.h"
#include "Effect.h"
@ -47,7 +53,15 @@ void mqtt_callback(char* complete_topic, byte* pl, unsigned int length) {
boolean mqtt_connect() {
char client_id[30];
snprintf(client_id, 30, HOSTNAME, ESP.getChipId());
int chipid;
#if defined( ESP8266 )
chipid = ESP.getChipId();
#elif defined( ESP32 )
chipid = ESP.getEfuseMac() & 0xFFFFFF;
#else
#error Neither ESP32 nor ESP8266 set.
#endif
snprintf(client_id, 30, HOSTNAME, chipid);
LOG("MQTT * Connecting to MQTT server with client id "); LOGln(client_id);
if (mqtt_client.connect(client_id, MQTT_USER, MQTT_PASS)) {
LOGln("MQTT * Connected.");

View File

@ -1,4 +1,12 @@
#include <ArduinoOTA.h>
#if defined( ESP8266 )
#include <ESP8266mDNS.h>
#elif defined( ESP32 )
#include <ESPmDNS.h>
#else
#error Neither ESP32 nor ESP8266 set!
#endif
#include <ArduinoOTA.h>
#include "config.h"
void ota_setup() {
@ -27,7 +35,16 @@ void ota_setup() {
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
char client_id[30];
snprintf(client_id, 30, HOSTNAME, ESP.getChipId());
int chipid;
#if defined( ESP8266 )
chipid = ESP.getChipId();
#elif defined( ESP32 )
chipid = ESP.getEfuseMac() & 0xFFFFFF;
#else
#error Neither ESP32 nor ESP8266 set.
#endif
snprintf(client_id, 30, HOSTNAME, chipid);
LOG("OTA * Starting OTA with client_id "); LOGln(client_id);
ArduinoOTA.setHostname(client_id);
ArduinoOTA.begin();

View File

@ -1,7 +1,4 @@
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ArduinoOTA.h>
#include <SimpleList.h>
#include "ntp.h"

View File

@ -1,5 +1,9 @@
#include <Arduino.h>
#include <ESP8266WiFi.h>
#if defined( ESP8266 )
#include <ESP8266WiFi.h>
#elif defined( ESP32 )
#include <WiFi.h>
#endif
#include "wifi.h"
#include "config.h"