Skip to content

Commit 2cebcf3

Browse files
committed
fix compilation on esp8266
1 parent 10cf2d5 commit 2cebcf3

File tree

2 files changed

+44
-28
lines changed

2 files changed

+44
-28
lines changed

platformio.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ build_flags =
2626
lib_deps =
2727
https://github.com/tzapu/WiFiManager
2828
https://github.com/marvinroger/ESP8266TrueRandom
29-
https://github.com/guido4096/espsoftwareserial.git#add-startbit-timestamp
29+
vshymanskyy/Preferences@^2.1.0
3030

3131
[env:esp12e-ota]
3232
extends = env:esp12e

src/main.cpp

+43-27
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ Preferences preferences;
2222
#define PWM_FREQ 10000
2323
#define PWM_RESOLUTION 8
2424

25+
#ifdef ESP32
2526
TaskHandle_t Task1;
27+
#endif
2628

2729
WiFiManager wifiManager(Serial1);
2830
WiFiManagerParameter param_pwm_value("pwm_value", "PWM value", "", 6);
@@ -51,10 +53,12 @@ int random_ch(){
5153
#endif
5254
}
5355

56+
#ifdef ESP32
5457
void on_connected(WiFiEvent_t event, WiFiEventInfo_t info){
5558
lastConnectTime = millis();
5659
reconnectCount++;
5760
}
61+
#endif
5862

5963
void wdt_start() {
6064
#ifdef ESP32
@@ -136,45 +140,49 @@ void loop_duration() {
136140
}
137141
}
138142

139-
void data_loop(void * pvParameters){
140-
while(1){
141-
loop_duration();
143+
void data_process(){
144+
loop_duration();
142145

143-
//check clients for data
144-
for (int i = 0; i < MAX_SRV_CLIENTS; i++){
145-
handleClient(&serverClients[i]);
146-
handleEnhClient(&enhClients[i]);
147-
}
146+
//check clients for data
147+
for (int i = 0; i < MAX_SRV_CLIENTS; i++){
148+
handleClient(&serverClients[i]);
149+
handleEnhClient(&enhClients[i]);
150+
}
148151

149-
//check queue for data
150-
BusType::data d;
151-
if (Bus.read(d)) {
152-
for (int i = 0; i < MAX_SRV_CLIENTS; i++){
153-
if (d._enhanced) {
154-
if (d._client == &enhClients[i]) {
155-
if (pushEnhClient(&enhClients[i], d._c, d._d, true)) {
156-
last_comms = millis();
157-
}
158-
}
159-
}
160-
else {
161-
if (pushClient(&serverClients[i], d._d)){
152+
//check queue for data
153+
BusType::data d;
154+
if (Bus.read(d)) {
155+
for (int i = 0; i < MAX_SRV_CLIENTS; i++){
156+
if (d._enhanced) {
157+
if (d._client == &enhClients[i]) {
158+
if (pushEnhClient(&enhClients[i], d._c, d._d, true)) {
162159
last_comms = millis();
163160
}
164-
if (pushClient(&serverClientsRO[i], d._d)){
161+
}
162+
}
163+
else {
164+
if (pushClient(&serverClients[i], d._d)){
165+
last_comms = millis();
166+
}
167+
if (pushClient(&serverClientsRO[i], d._d)){
168+
last_comms = millis();
169+
}
170+
if (d._client != &enhClients[i]) {
171+
if (pushEnhClient(&enhClients[i], d._c, d._d, d._logtoclient == &enhClients[i])){
165172
last_comms = millis();
166173
}
167-
if (d._client != &enhClients[i]) {
168-
if (pushEnhClient(&enhClients[i], d._c, d._d, d._logtoclient == &enhClients[i])){
169-
last_comms = millis();
170-
}
171-
}
172174
}
173175
}
174176
}
175177
}
176178
}
177179

180+
void data_loop(void * pvParameters){
181+
while(1){
182+
data_process();
183+
}
184+
}
185+
178186
void saveParamsCallback () {
179187
uint8_t new_pwm_value = atoi(param_pwm_value.getValue());
180188
if (new_pwm_value > 0){
@@ -212,7 +220,9 @@ void setup() {
212220
WiFi.enableAP(false);
213221
WiFi.begin();
214222

223+
#ifdef ESP32
215224
WiFi.onEvent(on_connected, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_CONNECTED);
225+
#endif
216226

217227
wifiManager.setSaveParamsCallback(saveParamsCallback);
218228
wifiManager.addParameter(&param_pwm_value);
@@ -241,7 +251,9 @@ void setup() {
241251

242252
last_comms = millis();
243253

254+
#ifdef ESP32
244255
xTaskCreate(data_loop, "data_loop", 10000, NULL, 1, &Task1);
256+
#endif
245257
}
246258

247259
bool handleStatusServerRequests() {
@@ -284,11 +296,15 @@ void loop() {
284296

285297
#ifdef ESP8266
286298
MDNS.update();
299+
300+
data_process();
287301
#endif
288302

289303
wdt_feed();
290304

305+
#ifdef ESP32
291306
wifiManager.process();
307+
#endif
292308

293309
if (WiFi.status() != WL_CONNECTED) {
294310
reset();

0 commit comments

Comments
 (0)