Skip to content

Commit afa565f

Browse files
committed
geändert: ESP-ValveControl/ESP-ValveControl.ino
geändert: ESP-ValveControl/webUI.ino
1 parent a0bd5c6 commit afa565f

8 files changed

Lines changed: 131 additions & 9 deletions

File tree

ESP-ValveControl/DS18B20.ino

100644100755
File mode changed.

ESP-ValveControl/ESP-ValveControl.ino

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
* Doxygen: https://www.doxygen.nl/manual/docblocks.html \n
3939
*
4040
* Change Log:
41+
* 2024-03-11 v0.8
42+
* - Added data logger: <IP>/logdata? reads curr_log[] and bemf_log[] from PIC.
43+
* - Added VBsum to "info?" for testing BEMF sum-up for position control.
4144
* 2024-01-29 v0.7.1
4245
* - Processing of flags.version moved to the end of "else-if". (A failed bootload could not be
4346
* repeated, because the initialized "flags.version" always took priority and never was worked off.
@@ -116,6 +119,7 @@ extern int setup_ReadINI (const char *path);
116119
extern int setup_WriteCstring (const char *path, const char *identifier, char *s);
117120

118121
// *** private function prototypes
122+
extern void getPIClogdata (void);
119123
extern void getPICversion (void);
120124

121125
// *** data type, constant and macro definitions
@@ -139,7 +143,7 @@ struct FLAGS //!< flags to start tasks within loop()
139143
uint8_t save :1; //!< 3 exec save
140144
uint8_t bootload :1; //!< 4 update PIC firmware
141145
uint8_t version :1; //!< 5 update PIC version
142-
uint8_t :1; //!< 6
146+
uint8_t logdata :1; //!< 6 reads log data from PIC
143147
uint8_t :1; //!< 7
144148
};
145149

@@ -175,7 +179,7 @@ PubSubClient MQTTclient(espClient);
175179

176180
/** Global variables
177181
* =============== */
178-
char ESPversion[32] = "v0.7.1"; // Version of ESP-Firmware
182+
char ESPversion[32] = "v0.8"; // Version of ESP-Firmware
179183
char PICversion[32] = "NN"; // Version of PIC-Firmware
180184

181185
// WiFi credentials: Initial values are used for access point!
@@ -207,12 +211,13 @@ float tempC = 0.0; // temperature in Celsius (DS18B20)
207211
float dTemp = 0.0; // temperature adjust (ovc.ini)
208212
int position[numVZ + 1] = {-1, 0, 65, 36, 100 }; // actual VZ positions (index 0 is dummy)
209213
bool refset[numVZ + 1]; // home position set?
214+
int vbemf_sum[numVZ + 1];
210215

211216
// Vars sourced by (html) User Interface
212217
struct FLAGS flags; // processing flags (Web UI -> loop)
213218
int vz = 0; // selected valve zone (motor), [1 .. 4], 0 = none!
214219
int set_pos[numVZ + 1] = { -1, 0, 65, 36, 100 }; // valve set positions
215-
float max_mA[numVZ + 1] = { 0.0, 25.0, 25.0, 25.0, 25.0 }; // motor current limits [mA]
220+
float max_mA[numVZ + 1] = { 0.0, 30.0, 30.0, 30.0, 30.0 }; // motor current limits [mA]
216221

217222
char txbuf[64];
218223
char rxbuf[64];
@@ -342,6 +347,7 @@ void setup ()
342347
server.on("/bootload", HTTP_GET, webUI_bootload);
343348
server.on("/move", HTTP_GET, webUI_move);
344349
server.on("/home", HTTP_GET, webUI_home);
350+
server.on("/logdata", HTTP_GET, webUI_logdata);
345351
server.on("/info", HTTP_GET, webUI_info);
346352
server.on("/status", HTTP_GET, webUI_status);
347353
server.on("/save", HTTP_GET, webUI_save);
@@ -374,6 +380,7 @@ void loop ()
374380
{
375381
unsigned long LoopStamp = millis(); // used to run main loop with constant execution time
376382
int error;
383+
int ival32;
377384
uint16_t uval;
378385
char buf[64];
379386
char *p;
@@ -431,7 +438,13 @@ void loop ()
431438
delay(500);
432439
}
433440
flags.bootload = 0;
434-
} // if flags.bootload
441+
}
442+
443+
else if (flags.logdata) // read logdata (curr_log[], bemf_log[]) from PIC
444+
{
445+
getPIClogdata();
446+
flags.logdata = 0;
447+
}
435448

436449
else if (flags.version) // Update PIC version info
437450
{
@@ -494,8 +507,21 @@ void loop ()
494507
refset[2] = REF2(status) ? 1 : 0;
495508
refset[3] = REF3(status) ? 1 : 0;
496509
refset[4] = REF4(status) ? 1 : 0;
510+
p = strstr(p, ",");
497511
}
498512
}
513+
if (p) // status word
514+
{
515+
if (sscanf(++p, "0x%08x", &ival32) == 1)
516+
{
517+
vbemf_sum[1] = ival32;
518+
// p = strstr(p, ",");
519+
}
520+
else vbemf_sum[1] = -1;
521+
}
522+
else vbemf_sum[1] = -2;
523+
524+
499525

500526
#ifdef DEBUG_OUTPUT_STATUS
501527
Serial.flush(); // Waits for the transmission of outgoing serial data to complete
@@ -732,3 +758,76 @@ void getPICversion (void)
732758
}
733759

734760
} // getPICversion()
761+
762+
763+
/** @brief Read LogData from PIC and save in LittleFS as file 'logdata.csv'
764+
*/
765+
void getPIClogdata (void)
766+
{
767+
unsigned long tstart;
768+
File logfile;
769+
String str;
770+
int error = 0;
771+
bool eol;
772+
char c;
773+
774+
logfile = LittleFS.open("logdata.csv", "w");
775+
if(logfile)
776+
{
777+
while (Serial.available() > 0) Serial.read(); // flush serial
778+
779+
sprintf(txbuf, "LogData?"); // send request to PIC
780+
error = cmd2pic();
781+
if (!error && (strncmp(rxbuf, "LogData:", 8) == 0)) // compare first N chars of response
782+
{
783+
do
784+
{
785+
rxbuf[0] = '\0'; // flush rxbuf
786+
nrx = 0;
787+
eol = 0;
788+
tstart = millis();
789+
for (error = 0; !eol && !error; )
790+
{
791+
while (Serial.available() > 0 && !eol)
792+
{
793+
c = Serial.read();
794+
if (c == '\r') continue; // skip
795+
if (c == '\n')
796+
{
797+
if (nrx < 2) continue;
798+
eol = true;
799+
c = '\0';
800+
}
801+
if (nrx < sizeof(rxbuf)) // if not buffer overflow
802+
{
803+
rxbuf[nrx++] = c; // store received char in rxbuf, increment count
804+
}
805+
else rxbuf[sizeof(rxbuf) - 1] = '\0'; // terminate rxbuf
806+
} // while
807+
808+
if ((millis() - tstart) > MAX_ACK_TIME)
809+
{
810+
error = -1; // timeout?
811+
}
812+
server.handleClient(); // process WebUI during reception
813+
} // for
814+
815+
if (eol) // we received a record
816+
{
817+
logfile.println(rxbuf);
818+
// logfile.writeString(rxbuf);
819+
}
820+
server.handleClient(); // mandatory
821+
} while (!error); // read until timeout, don't use fix limit
822+
OLED_show(1, (char *)"Logfile complete!");
823+
}
824+
logfile.print("Error: ");
825+
logfile.println(error);
826+
logfile.close();
827+
}
828+
else
829+
{
830+
OLED_show(1, (char *)"Can't create logfile");
831+
}
832+
833+
} // getPIClogdata()

ESP-ValveControl/LittleFS.ino

100644100755
File mode changed.

ESP-ValveControl/OLED.ino

100644100755
File mode changed.

ESP-ValveControl/build/esp8266.esp8266.d1_mini_clone/ESP-ValveControl_v0.7.1.bin renamed to ESP-ValveControl/build/esp8266.esp8266.d1_mini_clone/ESP-ValveControl_v0.8.bin

375 KB
Binary file not shown.

ESP-ValveControl/fw.ino

100644100755
File mode changed.

ESP-ValveControl/setup.ino

100644100755
File mode changed.

ESP-ValveControl/webUI.ino

100644100755
Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,28 @@ void webUI_bootload (void)
6969
} // webUI_bootload ()
7070

7171

72+
/** @brief Handler for logdata request.
73+
*/
74+
void webUI_logdata ()
75+
{
76+
char buf[128];
77+
String htmlPage;
78+
htmlPage.reserve(128); // prevent ram fragmentation
79+
80+
htmlPage = F("Requesting LogData from PIC Controller...\n");
81+
htmlPage += "Please allow approx. 5 seconds for completion,\n";
82+
htmlPage += "then read file 'logdata.csv' from LittleFS.\n";
83+
84+
server.send(200, "text/plain", htmlPage);
85+
86+
//server.sendHeader("Access-Control-Allow-Origin","*");
87+
server.send(200, "text/plain", htmlPage);
88+
89+
flags.logdata = 1;
90+
91+
} // webUI_logdata ()
92+
93+
7294
/** @brief Handler for MOVE. Arguments: <ESP_IP>/move?vz=[1..4]&set_pos=[0..100]&max_mA=[0.0 .. 100.0]
7395
*/
7496
void webUI_move ()
@@ -167,11 +189,12 @@ void webUI_info ()
167189

168190
htmlPage = F(
169191
"{ \n"
170-
"\"ESP\": \"" ); htmlPage += ESPversion; htmlPage += F("\",\n"
171-
"\"PIC\": \"" ); htmlPage += PICversion; htmlPage += F("\",\n"
172-
"\"SSID\": \""); htmlPage += ssid; htmlPage += F("\",\n"
173-
"\"dTemp\": \""); htmlPage += dTemp; htmlPage += F("\",\n"
174-
"\"RSSI\": \""); htmlPage += rssi; htmlPage += F(" dBm\"\n" // no comma at end
192+
"\"ESP\": \"" ); htmlPage += ESPversion; htmlPage += F("\",\n"
193+
"\"PIC\": \"" ); htmlPage += PICversion; htmlPage += F("\",\n"
194+
"\"SSID\": \""); htmlPage += ssid; htmlPage += F("\",\n"
195+
"\"dTemp\": \""); htmlPage += dTemp; htmlPage += F("\",\n"
196+
"\"RSSI\": \""); htmlPage += rssi; htmlPage += F(" dBm\",\n" // no comma at end
197+
"\"VBsum\": \""); htmlPage += vbemf_sum[1]; htmlPage += F("\"\n" // no comma at end
175198
"}\n");
176199

177200
//server.sendHeader("Access-Control-Allow-Origin","*");

0 commit comments

Comments
 (0)