From 30a463dfabfc861d9907a11f62e275912b88cbdd Mon Sep 17 00:00:00 2001 From: Youen Date: Sun, 9 Jun 2024 12:57:19 +0200 Subject: [PATCH] More precise wheel circumference, and added mDNS --- ESP32/src/vehicle-monitor.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ESP32/src/vehicle-monitor.cpp b/ESP32/src/vehicle-monitor.cpp index 9d64ec0..80f1d3f 100644 --- a/ESP32/src/vehicle-monitor.cpp +++ b/ESP32/src/vehicle-monitor.cpp @@ -9,6 +9,7 @@ #include "Info.h" #include "utils.h" +#include #include #include #include @@ -37,9 +38,11 @@ const int8_t debugLedPin = 2; const int8_t I2C_SDA = 15; const int8_t I2C_SCL = 4; -const float wheelDiameterInches = 20; +//const float wheelDiameterInches = 20; +//const float wheelTotalCircumeferenceMeters = wheelDiameterInches * 0.0254f * 3.1415f +const float wheelTotalCircumeferenceMeters = 1.60f; // measuring how much the vehicle advances for one turn of the wheel is more precise than calculating from the wheel diameter const int numImpulsesPerTurn = 2; -const float wheelCircumferenceMeters = wheelDiameterInches * 0.0254f * 3.1415f / (float)numImpulsesPerTurn; +const float wheelCircumferenceMeters = wheelTotalCircumeferenceMeters / (float)numImpulsesPerTurn; const uint32_t wheelCircumferenceMillimeters = (uint32_t)(wheelCircumferenceMeters * 1000.0f + 0.5f); Status status; @@ -188,6 +191,7 @@ void setup() } // Set WiFi mode to both AccessPoint and Station + WiFi.setHostname("vmon"); // this doesn't work when connecting to a mobile android hotspot (it can't resolve the hostname), but it should work with most routers allowing to access the app on https://vmon WiFi.mode(WIFI_AP_STA); // Create the WiFi Access Point @@ -205,6 +209,9 @@ void setup() // Also connect as a station (if the configured remote access point is in range) connectWifi(); + Serial.print("hostname: "); + Serial.println(WiFi.getHostname()); + OTA.begin(); #if ENABLE_GPS_COORDINATES @@ -236,6 +243,18 @@ void handle_wifi_connection() DebugLog.print(WiFi.SSID().c_str()); DebugLog.print("), ip="); DebugLog.println(WiFi.localIP()); + + // mDNS can help in case the router does not correctly handle local DNS after assigning an IP address via DHCP + // It works by broadcasting a request for a host name on the local network, and the device directly sends its IP address in response + // Unfortunately, some systems do not support mDNS (e.g. Android), so they won't use it at all. + // To access through mDNS, remember to add the ".local" suffix to the host name (for example if host name is "vmon", access it at URL "https://vmon.local") + Serial.print("Starting mDNS server with hostname \""); + Serial.print(WiFi.getHostname()); + Serial.println("\""); + if(!MDNS.begin(WiFi.getHostname())) + { + Serial.println("Error starting mDNS"); + } } else if(newWifiStatus == WL_DISCONNECTED) {