Browse Source

More precise wheel circumference, and added mDNS

master
Youen 6 months ago
parent
commit
30a463dfab
  1. 23
      ESP32/src/vehicle-monitor.cpp

23
ESP32/src/vehicle-monitor.cpp

@ -9,6 +9,7 @@
#include "Info.h"
#include "utils.h"
#include <ESPmDNS.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <FS.h>
@ -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)
{

Loading…
Cancel
Save