n3roGit / DPVControl

Your DIY diving vehicle controlled by ESP32
GNU General Public License v3.0
4 stars 1 forks source link

[FEATURE] Write long time Data - PRIO 3 #18

Open n3roGit opened 7 months ago

n3roGit commented 7 months ago

https://github.com/siara-cc/esp32_arduino_sqlite3_lib https://medium.com/@ladolcefarniente/save-data-input-to-spiffs-with-esp32-and-arduino-ide-9e37011d7a91

Ideally, we can store a lot of data during operation on the 4MB memory of the ESP in order to analyze it after use. a possible variant could be to use the library linked above.

Spontaneously I can think of the following data for the database:

I

happyherp commented 7 months ago

version on the branch starts a csv-file on startup. Every second we record time and temperature and write to it. Every startup uses a new file. As far as I can tell there is no easy way to access the file system.

n3roGit commented 7 months ago

beepSequence:1 still in standby: 1 Connected to VESC. E (1027) SPIFFS: mount failed, -10025 writing to /datalog/data_0.csv Listing directory: /datalog FILE: data_0.csv SIZE: 0 Booting finished! beepSequence:1 currentMotorSpeed: 0.00 Creating datapoint Creating datapoint Creating datapoint Creating datapoint Creating datapoint Creating datapoint

i got this after flashing

happyherp commented 7 months ago

yep. that means its writing to a file. Now how do we read it? I would do it via wifi.

n3roGit commented 7 months ago

Yes with wifi

happyherp commented 7 months ago

I'll start the wifi implementation in this issue then.

I like the AdvancedWebsocket better than working directly with the http-stream and having to write and parse http-headers myself like they do here: https://randomnerdtutorials.com/esp32-web-server-arduino-ide/

happyherp commented 7 months ago

Having some trouble here .Stuck in this loop

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    Serial.print(WiFi.status());
  }

Output is status:1(WL_NO_SSID_AVAIL) and stays there.

This guys seems to have a similiar problem: https://forum.arduino.cc/t/wifi-stopped-connecting-esp8266/593080/3 and fixed it by using another board firmware, I think.

54758fa9469cf5dd64692999ea0452106abe8c1a this is the code i tried. @n3roGit can you check it out?

n3roGit commented 7 months ago

This is because in this configuration the esp tries to dial into your wifi. However, we want to use the AP mode.

Have a look here: https://github.com/n3roGit/DPVControl/issues/20

That's what I was referring to =)

Changing the Wi-Fi mode: Change WiFi.mode(WIFI_STA); to WiFi.mode(WIFI_AP); to set the ESP32 to AP mode.

Set up the access point: Use WiFi.softAP(ssid, password); to set up the access point with your SSID and password. Remove WiFi.begin(ssid, password); as this function is used to connect to an existing Wi-Fi network.

Configure the IP address for the AP: In AP mode, you can set a static IP address as the ESP32 is the server. Use WiFi.softAPIP() to get the IP address of the ESP32 in AP mode.

Here is what your webSetup function might look like after the changes:

cpp Copy code void webSetup(){ WiFi.mode(WIFI_AP); WiFi.softAP(ssid, password);

Serial.println(""); Serial.print("Access Point started, SSID: "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.softAPIP());

if (MDNS.begin("esp32")) { Serial.println("MDNS responder started"); }

server.on("/", handleRoot); server.on("/inline", []() { server.send(200, "text/plain", "this works as well"); }); server.onNotFound(handleNotFound); server.begin(); Serial.println("HTTP server started"); } Make sure that you adjust the password and SSID of your access point accordingly. If you do not explicitly specify the IP address of the ESP32 in AP mode, an IP address such as 192.168.4.1 is assigned by default.

happyherp commented 5 months ago

We will need some kind of templating library to insert things into the html. There is the standard https://github.com/plapointe6/EspHtmlTemplateProcessor . But I don't think it will be enough.

I would like to try https://github.com/me-no-dev/ESPAsyncWebServer . But that requires plattformIO, which is another vsCode plugin. So i will try that.

happyherp commented 5 months ago

I spent a lot of time trying to port the project to plattformIO, but failed. It wont find the ClickButton.h even though i included it. Can you give it a try @n3roGit

n3roGit commented 5 months ago

I can try to do that. Can't we use the web server that is currently working?

happyherp commented 3 months ago

image

I added the missing fields to the csv file. Motor values are all dummy, as I don't have one on my board. You should run it with the real thing, so we can adjust the formatting. @n3roGit

n3roGit commented 3 months ago

2024-03-10 10_46_41-DPVController ino - DPVControl - Visual Studio Code logs (4).csv

Looks great. i have niticed that i have two "1" csv files after delete. and i have attached the new generated log =)

happyherp commented 3 months ago

the log looks ok, i would say. maybe we could display motor rpm without decimal places...

happyherp commented 3 months ago

also added: display of file size in list; logging of led lamp state.

happyherp commented 3 months ago

also logging: motorstate, speedsetting.

n3roGit commented 3 months ago

Really Great!

Please add:

Battery Percentage motorState OverAllRuntime WaterSensor State (Front and Back)

n3roGit commented 3 months ago

image image

Looks Nice. Why i have two files frome time to time?

happyherp commented 3 months ago

Looks Nice. Why i have two files frome time to time?

Not sure. But it is the file we are currently writing to. Can you live with that?

n3roGit commented 3 months ago

Looks Nice. Why i have two files frome time to time?

Not sure. But it is the file we are currently writing to. Can you live with that?

Yes its OK

n3roGit commented 3 months ago

Really Great!

Please add:

Battery Percentage motorState OverAllRuntime WaterSensor State (Front and Back)

Only this would be usefull

happyherp commented 3 months ago

OverAllRuntime

That one is a bit more work. The timer resets with the machine. I would need to create a file to get the value from the last run. And regularly overwrite it to have the value for the next time, because we could be turned off at any moment. Please make a separate ticket for that one.

Battery Percentage WaterSensor State (Front and Back)

Those are easy.. will add.

n3roGit commented 3 months ago

I have a simple solution to create graphs from the CSV:

https://webutility.io/csv-to-chart-online image

Simply upload the file there as it is.

n3roGit commented 3 months ago

@happyherp I have found another critical error in the current firmware. For some reason, both water sensors go TRUE. Even a restart does not fix this.

happyherp commented 3 months ago

I have found another critical error in the current firmware. For some reason, both water sensors go TRUE. Even a restart does not fix this.

Weird. I am pretty sure, that I did not change the code. But it looked weird to me as well, because it had SENSOR == LOW.

I negated the sensors. Try again?

n3roGit commented 3 months ago

I have found another critical error in the current firmware. For some reason, both water sensors go TRUE. Even a restart does not fix this.

Weird. I am pretty sure, that I did not change the code. But it looked weird to me as well, because it had SENSOR == LOW.

I negated the sensors. Try again?

No this isnt the solution. after the following commit its broken:

https://github.com/n3roGit/DPVControl/commit/0706cedec54c6233f299dc0e2ed16455dcd82113

n3roGit commented 3 months ago

I suspect that it only occurs when the VESC is connected. It also looks like this in the log.

If I leave the VESC connected while the ESP is already receiving power via USB, I can reproduce the error.

Failed to get VESC data!: 0 Loop took: 101 Failed to get VESC data!: 0 Loop took: 101 Failed to get VESC data!: 0 Loop took: 101 Failed to get VESC data!: 0 Loop took: 101 Failed to get VESC data!: 0 Loop took: 101 Failed to get VESC data!: 0 Loop took: 101 Failed to get VESC data!: 0 Loop took: 101 Failed to get VESC data!: 0 Loop took: 101 Failed to get VESC data!: 0 Loop took: 101 Loop took: 116 beepSequence:12121212 WARNING LEAK: 12121212 beepSequence:12121212 WARNING LEAK: 12121212 beepSequence:12121212 WARNING LEAK: 12121212 beepSequence:12121212 WARNING LEAK: 12121212 beepSequence:12121212 WARNING LEAK: 12121212 beepSequence:12121212 WARNING LEAK: 12121212 beepSequence:12121212 WARNING LEAK: 12121212 beepSequence:12121212 WARNING LEAK: 12121212 beepSequence:12121212 WARNING LEAK: 12121212 beepSequence:12121212 WARNING LEAK: 12121212 beepSequence:12121212