Skip to content

Commit 1e02218

Browse files
committed
misc fixes
1 parent 653cef0 commit 1e02218

File tree

6 files changed

+402
-38
lines changed

6 files changed

+402
-38
lines changed

httpportal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ WiFiManager portal(Logger); // use netlog for logging wm
1010
// WiFiManager portal;
1111

1212
void begin_httpportal(){
13+
// portal.setDebugLevel();
14+
// portal.setDebugOutput(true);
1315
portal.startWebPortal();
1416
}
1517

@@ -22,7 +24,7 @@ void process_httpportal(){
2224
}
2325

2426
void init_httpportal(String title = "",bool begin = true){
25-
portal.setDebugOutput(true,"[HTTPP] ");
27+
portal.setDebugOutput(true,"[HTTPD] ");
2628
// invert theme, dark
2729
portal.setDarkMode(true);
2830
std::vector<const char *> menu = {"wifi","param","info","sep","update","restart","exit"};

mqtt.h

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,37 @@ const char* clientID = "";
3939
bool mqttconnected = false;
4040

4141
long lastReconnectAttempt = 0;
42-
uint16_t mqttretry = 5000;
42+
uint32_t mqttretry = 10000;
43+
44+
// Possible values for client.state()
45+
// #define MQTT_CONNECTION_TIMEOUT -4
46+
// #define MQTT_CONNECTION_LOST -3
47+
// #define MQTT_CONNECT_FAILED -2
48+
// #define MQTT_DISCONNECTED -1
49+
// #define MQTT_CONNECTED 0
50+
// #define MQTT_CONNECT_BAD_PROTOCOL 1
51+
// #define MQTT_CONNECT_BAD_CLIENT_ID 2
52+
// #define MQTT_CONNECT_UNAVAILABLE 3
53+
// #define MQTT_CONNECT_BAD_CREDENTIALS 4
54+
// #define MQTT_CONNECT_UNAUTHORIZED 5
4355

4456
void MQTTreconnect() {
45-
46-
// Loop until we're reconnected
47-
// this is blocking
4857
if (!client.connected()) {
4958
// while (!client.connected()) {
5059
if(debug_mqtt) Logger.println("[MQTT] Connecting...");
5160
// Attempt to connect
5261
if (client.connect(clientID)) {
62+
mqttconnected = true;
5363
Logger.println("[MQTT] Connected");
5464
// Once connected, publish an announcement...
5565
client.publish("TESTOUT", "hello world");
5666
// ... and resubscribe
5767
client.subscribe("CMD");
5868
} else {
59-
Logger.print("[ERROR] [MQTT] failed, rc="); // @todo we get here but no actual reconnnect loop, why?
69+
Logger.print("[ERROR] [MQTT] failed, rc="); // @todo we get here but no actual reconnnect
6070
Logger.println(client.state());
61-
// Wait 5 seconds before retrying
62-
delay(5000);
6371
}
64-
delay(100);
65-
}
72+
}
6673
}
6774

6875
void MQTTcallback(char* topic, byte* payload, unsigned int length) {
@@ -95,12 +102,7 @@ void mqtt_checkconn(){
95102
if (now - lastReconnectAttempt > mqttretry) {
96103
Logger.println("[MQTT] try client re-connect");
97104
lastReconnectAttempt = now;
98-
// Attempt to reconnect
99-
// if (mqttWiFiReconnect()) {
100-
lastReconnectAttempt = 0;
101-
MQTTreconnect();
102-
// client.connect(clientID);
103-
// }
105+
MQTTreconnect();
104106
}
105107
} else {
106108
// Client connected
@@ -294,13 +296,13 @@ void MQTT_pub(String topic, String sensor, String value){
294296
// add free heap
295297
void MQTT_pub_device(){
296298
if(debug_mqtt) Logger.println("[MQTT] Publish Device");
299+
MQTT_pub("device","uptime_s",(String)(millis()/1000));
297300
MQTT_pub("device","rssi",(String)getRSSIasQuality());
301+
MQTT_pub("device","heap",(String)ESP.getFreeHeap());
302+
// MQTT_pub("device","hall",(String)hallRead());
298303
#ifdef ESP32
299-
// MQTT_pub("device","hall",(String)hallRead()); // USES PINS 36,39
300304
MQTT_pub("device","temp",(String)temperatureRead());
301-
// MQTT_pub("device","adc_1",(String)analogRead(39));
302305
#endif
303-
MQTT_pub("device","uptime_s",(String)(millis()/1000));
304306
MQTT_pub_send("device");
305307
}
306308

neoindicator.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ void indSetColor(uint8_t r,uint8_t g,uint8_t b){
131131
indSetColor(ind.Color(r,g,b));
132132
}
133133

134+
// void setPixelBrightness(uint32_t n, uint32_t a){
135+
// }
136+
137+
// void indSetBrightness(uint8_t a){
138+
// uint32_t c = strip.getPixelColor(0);
139+
// // if(DEBUG_neoind)Serial.println("[IND] set ind color brightness:"+(String) ind.Color(r,g,b));
140+
// setPixelColorAlpha(n,c,a);
141+
// ind.setPixelBrightness
142+
// }
143+
144+
134145
void setIndColor(uint8_t r,uint8_t g,uint8_t b){
135146
indSetColor(r,g,b);
136147
}

neopixel_helper.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* All helpers need to be refactored to use neopixel objected passed in
3+
* kludge reassign strip to your obj etc and use as a shadow
4+
*/
15
#ifndef NEOPIXEL_HELPER_H
26
#define NEOPIXEL_HELPER_H
37

@@ -159,6 +163,7 @@ uint16_t randomBrightness(uint16_t a,uint8_t range){
159163
return b;
160164
}
161165

166+
// does not allow offsets 0-255
162167
uint16_t getBrightnessStep(uint8_t step, uint16_t numsteps){
163168
uint16_t brightness;
164169
// brightness = 255 - (step * (255/numsteps)); // linear
@@ -303,6 +308,7 @@ void fadeTo(uint32_t c,uint16_t duration){
303308
fade(getPixelColor(0),c,duration);
304309
}
305310

311+
// stepping non blocking fader
306312
uint32_t getFadeStep(uint32_t startColor, uint32_t endColor, uint16_t steps, uint16_t step){
307313
int16_t redDiff = red(endColor) - red(startColor);
308314
int16_t greenDiff = green(endColor) - green(startColor);
@@ -315,7 +321,8 @@ uint32_t getFadeStep(uint32_t startColor, uint32_t endColor, uint16_t steps, uin
315321
blueValue = (int16_t)blue(startColor) + (blueDiff * step / steps);
316322
whiteValue = (int16_t)white(startColor) + (whiteDiff * step / steps);
317323

318-
return color(redValue, greenValue, blueValue,whiteValue);
324+
// return color(redValue, greenValue, blueValue,whiteValue);
325+
return color(redValue, greenValue, blueValue);
319326
}
320327

321328
void flasher(uint32_t colorA, uint32_t colorB,int waitA, int waitB){

0 commit comments

Comments
 (0)