Renamed ota_name into username and rewrite udp cloud

This commit is contained in:
CommanderRedYT
2022-10-05 23:12:19 +02:00
parent 44100bcc0a
commit 219b995695
24 changed files with 187 additions and 119 deletions

View File

@ -1,5 +1,5 @@
set(BOBBY_APP_NAME bobbyquad_allfeatures)
set(BOBBY_DEFAULT_OTA_NAME allfeatures)
set(BOBBY_DEFAULT_USERNAME allfeatures)
add_definitions(
-DUSER_SETUP_LOADED=1

View File

@ -1,5 +1,5 @@
set(BOBBY_APP_NAME bobbyquad_aveexy)
set(BOBBY_DEFAULT_OTA_NAME aveexy)
set(BOBBY_DEFAULT_USERNAME aveexy)
add_definitions(
-DUSER_SETUP_LOADED=1

View File

@ -1,5 +1,5 @@
set(BOBBY_APP_NAME bobbyquad_comred)
set(BOBBY_DEFAULT_OTA_NAME comred)
set(BOBBY_DEFAULT_USERNAMENAME comred)
add_definitions(
-DUSER_SETUP_LOADED=1

View File

@ -1,5 +1,5 @@
set(BOBBY_APP_NAME bobbyquad_comred_new)
set(BOBBY_DEFAULT_OTA_NAME comred_new)
set(BOBBY_DEFAULT_USERNAME comred_new)
add_definitions(
-DUSER_SETUP_LOADED=1

View File

@ -1,5 +1,5 @@
set(BOBBY_APP_NAME bobbyquad_feedc0de)
set(BOBBY_DEFAULT_OTA_NAME feedc0de)
set(BOBBY_DEFAULT_USERNAME feedc0de)
set(BOBBYCAR_BUILDFLAGS
# Pins

View File

@ -1,5 +1,5 @@
set(BOBBY_APP_NAME bobbyquad_feedc0de)
set(BOBBY_DEFAULT_OTA_NAME feedc0de)
set(BOBBY_DEFAULT_USERNAME feedc0de)
set(BOBBYCAR_BUILDFLAGS
# Pins

View File

@ -1,5 +1,5 @@
set(BOBBY_APP_NAME bobbyquad_gernot)
set(BOBBY_DEFAULT_OTA_NAME gernot)
set(BOBBY_DEFAULT_USERNAME gernot)
add_definitions(
-DUSER_SETUP_LOADED=1

View File

@ -1,5 +1,5 @@
set(BOBBY_APP_NAME bobbyquad_greyhash)
set(BOBBY_DEFAULT_OTA_NAME greyhash)
set(BOBBY_DEFAULT_USERNAME greyhash)
add_definitions(
-DUSER_SETUP_LOADED=1

View File

@ -1,5 +1,5 @@
set(BOBBY_APP_NAME bobbyquad_mick)
set(BOBBY_DEFAULT_OTA_NAME mick)
set(BOBBY_DEFAULT_USERNAME mick)
add_definitions(
-DUSER_SETUP_LOADED=1

View File

@ -1,5 +1,5 @@
set(BOBBY_APP_NAME bobbyquad_nofeatures)
set(BOBBY_DEFAULT_OTA_NAME nofeatures)
set(BOBBY_DEFAULT_USERNAME nofeatures)
add_definitions(
-DUSER_SETUP_LOADED=1

View File

@ -1,5 +1,5 @@
set(BOBBY_APP_NAME bobbyquad_peter)
set(BOBBY_DEFAULT_OTA_NAME peter)
set(BOBBY_DEFAULT_USERNAME peter)
add_definitions(
-DUSER_SETUP_LOADED=1

View File

@ -1,5 +1,5 @@
set(BOBBY_APP_NAME bobbyquad_seatbot)
set(BOBBY_DEFAULT_OTA_NAME seatbot)
set(BOBBY_DEFAULT_USERNAME seatbot)
add_definitions(
-DUSER_SETUP_LOADED=1

View File

@ -1,5 +1,5 @@
set(BOBBY_APP_NAME testdevice)
set(BOBBY_DEFAULT_OTA_NAME testdevice)
set(BOBBY_DEFAULT_USERNAME testdevice)
add_definitions(
-DUSER_SETUP_LOADED=1

View File

@ -1,5 +1,5 @@
set(BOBBY_APP_NAME testdevice2)
set(BOBBY_DEFAULT_OTA_NAME testdevice2)
set(BOBBY_DEFAULT_USERNAME testdevice2)
add_definitions(
-DUSER_SETUP_LOADED=1

View File

@ -546,8 +546,8 @@ string(REPLACE "\n" " " GIT_MESSAGE "${GIT_MESSAGE}")
string(SUBSTRING "${GIT_MESSAGE}" 0 100 GIT_MESSAGE)
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
if(NOT DEFINED BOBBY_DEFAULT_OTA_NAME)
message(FATAL_ERROR "Please define BOBBY_DEFAULT_OTA_NAME")
if(NOT DEFINED BOBBY_DEFAULT_USERNAME)
message(FATAL_ERROR "Please define BOBBY_DEFAULT_USERNAME")
endif()
target_compile_options(${COMPONENT_TARGET}
@ -563,6 +563,6 @@ target_compile_options(${COMPONENT_TARGET}
-DGIT_SHORT_REV="${GIT_SHORT_REV}"
-DGIT_MESSAGE="${GIT_MESSAGE}"
-DGIT_BRANCH="${GIT_BRANCH}"
-DBOBBY_DEFAULT_OTA_NAME="${BOBBY_DEFAULT_OTA_NAME}"
-DBOBBY_DEFAULT_USERNAME="${BOBBY_DEFAULT_OTA_NAME}"
${BOBBYCAR_BUILDFLAGS}
)

View File

@ -129,7 +129,9 @@ struct CloudSendRateAccessor : public NewSettingsAccessor<int16_t> { ConfigWrapp
struct UdpCloudSendIntervalAccessor : public NewSettingsAccessor<int16_t> { ConfigWrapper<int16_t> &getConfig() const override { return configs.boardcomputerHardware.timersSettings.udpSendRateMs; } };
struct UdpCloudEnabledAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.udpCloudSettings.udpCloudEnabled; } };
struct CloudDebugEnableAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.udpCloudSettings.enableCloudDebug; } };
struct UdpCloudDebugEnableAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<bool> &getConfig() const override { return configs.udpCloudSettings.enableCloudDebug; } };
struct UdpCloudHostAccessor : public NewSettingsAccessor<std::string> { ConfigWrapper<std::string> &getConfig() const override { return configs.udpCloudSettings.udpCloudHost; } };
struct UdpCloudPortAccessor : public NewSettingsAccessor<uint16_t> { ConfigWrapper<uint16_t> &getConfig() const override { return configs.udpCloudSettings.udpCloudPort; } };
// DefaultMode
struct DefaultModeModelModeAccessor : public RefAccessorSaveSettings<UnifiedModelMode> { UnifiedModelMode &getRef() const override { return profileSettings.defaultMode.modelMode; } };
@ -268,3 +270,4 @@ struct FlipScreenAccessor : public NewSettingsAccessor<bool> { ConfigWrapper<boo
// Other
struct AnhaengerIdAccessor : public NewSettingsAccessor<uint16_t> { ConfigWrapper<uint16_t> &getConfig() const override { return configs.anhaenger_id; } };
struct UsernameAccessor : public NewSettingsAccessor<std::string> { ConfigWrapper<std::string> &getConfig() const override { return configs.otaUsername; } };

View File

@ -73,7 +73,7 @@ DebugMenu::DebugMenu()
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BATTERYDEBUG>, PushScreenAction<BatteryDebugMenu>, StaticMenuItemIcon<&bobbyicons::battery>>>();
if (configs.feature.udpcloud.isEnabled.value())
{
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_TOGGLECLOUDDEBUG>, BobbyCheckbox, CloudDebugEnableAccessor>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_TOGGLECLOUDDEBUG>, BobbyCheckbox, UdpCloudDebugEnableAccessor>>();
}
constructMenuItem<makeComponent<MenuItem, LastRebootReasonText, StaticFont<2>, DisabledColor, DummyAction>>();
#ifdef FEATURE_CAN

View File

@ -1,9 +1,11 @@
#include "settingsmenu.h"
// 3rdparty lib includes
#include "actions/pushscreenaction.h"
#include "actions/popscreenaction.h"
#include "icons/back.h"
#include <actions/popscreenaction.h>
#include <actions/pushscreenaction.h>
#include <changevaluedisplay_string.h>
#include <icons/back.h>
#include <textwithvaluehelper.h>
// local includes
#include "accessors/settingsaccessors.h"
@ -21,7 +23,6 @@
#include "displays/menus/featureflagsmenu.h"
#include "displays/menus/gitmenu.h"
#include "displays/menus/limitssettingsmenu.h"
#include "displays/menus/mainmenu.h"
#include "displays/menus/modessettingsmenu.h"
#include "displays/menus/networksettingsmenu.h"
#include "displays/menus/selectbuildservermenu.h"
@ -37,8 +38,6 @@
#include "icons/time.h"
#include "icons/update.h"
#include "icons/wifi.h"
#include "textwithvaluehelper.h"
#include "utils.h"
namespace {
constexpr char TEXT_SETTINGS[] = "Settings";
@ -56,6 +55,7 @@ constexpr char TEXT_MODESSETTINGS[] = "Modes settings";
constexpr char TEXT_CONTROLLERHARDWARESETTINGS[] = "Controller H/W settings";
constexpr char TEXT_BOARDCOMPUTERHARDWARESETTINGS[] = "Boardcomputer H/W settings";
constexpr char TEXT_FEATUREFLAGS[] = "Feature flags";
constexpr char TEXT_USERNAME[] = "Username"; // ota-name
constexpr char TEXT_ANHAENGER_ID[] = "Anhaenger ID";
constexpr char TEXT_AUTOCONNECTBMS[] = "Auto connect BMS";
constexpr char TEXT_BUZZER[] = "Buzzer";
@ -83,6 +83,14 @@ using AnhaengerIdChangeScreen = espgui::makeComponent<
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
>;
using UsernameChangeScreen = espgui::makeComponent<
BobbyChangeValueDisplay<std::string>,
espgui::StaticText<TEXT_USERNAME>,
UsernameAccessor,
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
>;
} // namespace
using namespace espgui;
@ -117,7 +125,8 @@ SettingsMenu::SettingsMenu()
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BOARDCOMPUTERHARDWARESETTINGS>, PushScreenAction<BoardcomputerHardwareSettingsMenu>, StaticMenuItemIcon<&bobbyicons::hardware>>>();
}
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_FEATUREFLAGS>, PushScreenAction<FeatureFlagsMenu>, StaticMenuItemIcon<&bobbyicons::demos>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_ANHAENGER_ID, AnhaengerIdAccessor>, espgui::PushScreenAction<AnhaengerIdChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_USERNAME>, PushScreenAction<UsernameChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_ANHAENGER_ID, AnhaengerIdAccessor>, PushScreenAction<AnhaengerIdChangeScreen>>>();
//#if defined(FEATURE_BLUETOOTH) && defined(FEATURE_BMS)
// constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_AUTOCONNECTBMS>, BobbyCheckbox, AutoConnectBmsAccessor>>();
//#endif

View File

@ -3,7 +3,7 @@
// 3rdparty lib includes
#include <actions/popscreenaction.h>
#include <actions/pushscreenaction.h>
#include <changevaluedisplay.h>
#include <changevaluedisplay_string.h>
#include <fmt/core.h>
#include <icons/back.h>
#include <menuitem.h>
@ -17,6 +17,8 @@ namespace {
constexpr char TEXT_UDPCLOUDSETTINGS[] = "UDP Cloud settings";
constexpr char TEXT_UDPCLOUDENABLED[] = "Udp Cloud enabled";
constexpr char TEXT_UDPSENDRATE[] = "Udp send rate";
constexpr char TEXT_UDPHOST[] = "Udp host";
constexpr char TEXT_UDPPORT[] = "Udp port";
constexpr char TEXT_BACK[] = "Back";
using UdpCloudSendRateChangeDisplay = espgui::makeComponent<
@ -26,6 +28,22 @@ using UdpCloudSendRateChangeDisplay = espgui::makeComponent<
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
>;
using UdpCloudHostChangeDisplay = espgui::makeComponent<
BobbyChangeValueDisplay<std::string>,
espgui::StaticText<TEXT_UDPHOST>,
UdpCloudHostAccessor,
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
>;
using UdpCloudPortChangeDisplay = espgui::makeComponent<
BobbyChangeValueDisplay<uint16_t>,
espgui::StaticText<TEXT_UDPPORT>,
UdpCloudPortAccessor,
espgui::ConfirmActionInterface<espgui::PopScreenAction>,
espgui::BackActionInterface<espgui::PopScreenAction>
>;
} // namespace
using namespace espgui;
@ -34,6 +52,8 @@ UdpCloudSettingsMenu::UdpCloudSettingsMenu()
{
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_UDPCLOUDENABLED>, BobbyCheckbox, UdpCloudEnabledAccessor>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_UDPSENDRATE>, PushScreenAction<UdpCloudSendRateChangeDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_UDPHOST>, PushScreenAction<UdpCloudHostChangeDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_UDPPORT>, PushScreenAction<UdpCloudPortChangeDisplay>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, PopScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>();
}

View File

@ -23,7 +23,7 @@ std::string defaultHostname()
std::string defaultUsername()
{
return fmt::format("bobby_{}", BOBBY_DEFAULT_OTA_NAME);
return fmt::format("bobby_{}", BOBBY_DEFAULT_USERNAME);
}
ConfigManager<ConfigContainer> configs;

View File

@ -324,10 +324,9 @@ public:
ConfigWrapperLegacy<int16_t> reverseBeepDuration1{500, DoReset, {}, "revBeepDur1" };
ConfigWrapperLegacy<std::string> cloudUrl {"ws://api.bobbycar.cloud/ws", DoReset, StringOr<StringEmpty, StringValidUrl>, "cloudUrl" };
ConfigWrapperLegacy<std::string> udpCloudHost {"updates.bobbycar.cloud", DoReset, {}, "udpCloudHost" };
ConfigWrapperLegacy<std::string> otaUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaUrl" };
ConfigWrapperLegacy<std::string> otaUsername {std::string{BOBBY_DEFAULT_OTA_NAME}, DoReset, {}, "otaUsername" };
ConfigWrapperLegacy<std::string> otaUsername {std::string{BOBBY_DEFAULT_USERNAME}, DoReset, {}, "otaUsername" };
ConfigWrapperLegacy<std::string> otaServerUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaServerUrl" };
ConfigWrapperLegacy<std::string> otaServerBranch {std::string{}, DoReset, {}, "otaServerBranch" };
std::array<ConfiguredOtaServer, 5> otaServers {
@ -376,9 +375,11 @@ public:
} cloudSettings;
struct {
ConfigWrapperLegacy<uint32_t> udpUid {0, DoReset, {}, "cloudUDPUid" };
ConfigWrapperLegacy<std::string> udpToken {std::string{}, DoReset, {}, "udpToken" };
ConfigWrapperLegacy<bool> udpCloudEnabled {false, DoReset, {}, "enUdpCloud" };
ConfigWrapperLegacy<bool> enableCloudDebug {false, DoReset, {}, "debugCloud" };
ConfigWrapperLegacy<uint16_t> udpCloudPort {24243, DoReset, {}, "udpCloudPort" };
ConfigWrapperLegacy<std::string> udpCloudHost {"updates.bobbycar.cloud", DoReset, {}, "udpCloudHost" };
} udpCloudSettings;
struct {
@ -671,7 +672,6 @@ public:
x(reverseBeepDuration1) \
\
x(cloudUrl) \
x(udpCloudHost) \
\
x(otaUrl) \
x(otaUsername) \
@ -719,9 +719,11 @@ public:
x(cloudSettings.cloudKey) \
x(cloudSettings.sendStatistic) \
\
x(udpCloudSettings.udpUid) \
x(udpCloudSettings.udpToken) \
x(udpCloudSettings.udpCloudEnabled) \
x(udpCloudSettings.enableCloudDebug) \
x(udpCloudSettings.enableCloudDebug) \
x(udpCloudSettings.udpCloudPort) \
x(udpCloudSettings.udpCloudHost) \
\
x(ledstrip.enableLedAnimation) \
x(ledstrip.enableBrakeLights) \

View File

@ -1,7 +1,7 @@
#pragma once
/*
* In this file there will be
* - a web-handler to get qr as plain text from http://qr.bobbycar.cloud/files/[OTA_NAME].qr that can be later triggered via in qrimportdisplay.h
* - a web-handler to get qr as plain text from http://qr.bobbycar.cloud/files/[USERNAME].qr that can be later triggered via in qrimportdisplay.h
* - getter and setter that use NVS
*/

View File

@ -1,22 +1,24 @@
#include "udpcloud.h"
// system includes
#include <esp_log.h>
#include <esp_ota_ops.h>
#include <lwip/dns.h>
// 3rd party includes
#include <ArduinoJson.h>
#include <FastLED.h>
#include <esp_ota_ops.h>
#include <espchrono.h>
#include <espwifistack.h>
#include <fmt/format.h>
// local includes
#include "udpsender.h"
#include "esp_log.h"
#include "fmt/format.h"
#include "globals.h"
#include "utils.h"
#include "lwip/dns.h"
#include "espchrono.h"
#include "battery.h"
#include "drivingstatistics.h"
#include "globals.h"
#include "newsettings.h"
#include "udpsender.h"
#include "utils.h"
using namespace std::chrono_literals;
@ -25,6 +27,8 @@ constexpr const char * const TAG = "bobbycloud";
espchrono::millis_clock::time_point timestampLastFailed;
espchrono::millis_clock::time_point lastSend;
uint8_t packageType{0}; // cycle through packages.
} // namespace
// Little "flash" on statusdisplay when udp stuff is happening
@ -40,99 +44,121 @@ void udpCloudUpdate()
if (!configs.feature.udpcloud.isEnabled.value())
return;
if (configs.udpCloudSettings.udpCloudEnabled.value() && configs.udpCloudSettings.udpUid.touched())
if (configs.udpCloudSettings.udpCloudEnabled.value() && configs.udpCloudSettings.udpToken.touched())
sendUdpCloudPacket();
}
std::string buildUdpCloudJson()
std::optional<std::string> buildUdpCloudJson()
{
static std::string version_string;
if (version_string.empty() || version_string == "-")
StaticJsonDocument<512> doc;
switch (++packageType)
{
if (const esp_app_desc_t *app_desc = esp_ota_get_app_description())
{
version_string = app_desc->version;
}
else
{
version_string = "-";
}
default:
packageType = 0;
case 0:
{
// uptime, potis
const auto uptime = espchrono::millis_clock::now().time_since_epoch() / 1ms;
doc["upt"] = uptime;
if (gas)
doc["pcg"] = *gas; // poti calculated gas
if (raw_gas)
doc["prg"] = *raw_gas; // poti raw gas
if (brems)
doc["pcb"] = *brems; // poti calculated brems
if (raw_brems)
doc["prb"] = *raw_brems; // poti raw brems
doc["loc"] = isLocked;
doc["mdr"] = drivingStatistics.meters_driven;
doc["mdt"] = drivingStatistics.totalMeters;
doc["cdt"] = drivingStatistics.currentDrivingTime / 1ms;
doc["sha"] = GIT_REV;
break;
}
StaticJsonDocument<1024> doc;
std::string buf;
const auto uptime = espchrono::millis_clock::now().time_since_epoch() / 1ms;
case 1:
{
float watt{0};
const auto avgVoltage = controllers.getAvgVoltage();
if(avgVoltage)
watt = sumCurrent * *avgVoltage;
// const auto w_per_kmh = watt / avgSpeedKmh;
// User ID
doc["uid"] = configs.udpCloudSettings.udpUid.value();
doc["upt"] = uptime;
const auto addController = [&](const Controller &controller, const bool isBack) {
if (const auto avgVoltage = controllers.getAvgVoltage(); avgVoltage)
{
doc["bap"] = getBatteryPercentage(*avgVoltage, BatteryCellType(configs.battery.cellType.value()));
doc["bav"] = *avgVoltage; // battery voltage
doc["pwr"] = sumCurrent * *avgVoltage; // total watt
}
doc["whl"] = getRemainingWattHours(); // watt hours left
doc["kml"] = getRemainingWattHours() / configs.battery.watthoursPerKilometer.value(); // calculated kilometers left
doc["ekm"] = getEstimatedKmLeft(); // kilometers left live calculation
break;
}
case 2:
{
const auto &controller = controllers.front;
if (controller.feedbackValid)
{
auto arr = doc.createNestedObject(!isBack ? "f":"b");
// Voltage
arr["V"] = controller.getCalibratedVoltage();
doc["fbv"] = controller.getCalibratedVoltage();
// Amperes
arr["lA"] = fixCurrent(controller.feedback.left.dcLink);
arr["rA"] = fixCurrent(controller.feedback.right.dcLink);
doc["fla"] = fixCurrent(controller.feedback.left.dcLink);
doc["fra"] = fixCurrent(controller.feedback.right.dcLink);
// Temperature
arr[!isBack ? "fT":"bT"] = fixBoardTemp(controller.feedback.boardTemp);
doc["fbt"] = fixBoardTemp(controller.feedback.boardTemp);
// Errors
arr[!isBack ? "flE":"blE"] = controller.feedback.left.error;
arr[!isBack ? "frE":"brE"] = controller.feedback.right.error;
doc["fle"] = controller.feedback.left.error;
doc["fre"] = controller.feedback.right.error;
// Speed
arr[!isBack ? "flS":"blS"] = convertToKmh(controller.feedback.left.speed) * (controller.invertLeft?-1:1);
arr[!isBack ? "frS":"brS"] = convertToKmh(controller.feedback.right.speed) * (controller.invertRight?-1:1);
doc["fls"] = convertToKmh(controller.feedback.left.speed) * (controller.invertLeft?-1:1);
doc["frs"] = convertToKmh(controller.feedback.right.speed) * (controller.invertRight?-1:1);
}
else
{
doc[!isBack ? "f":"b"] = nullptr;
return std::nullopt;
}
};
addController(controllers.front, false);
addController(controllers.back, true);
// Potis
break;
}
case 3:
{
auto arr = doc.createNestedObject("p");
if (gas)
arr["g"] = *gas;
if (raw_gas)
arr["rg"] = *raw_gas;
if (brems)
arr["b"] = *brems;
if (raw_brems)
arr["rb"] = *raw_brems;
const auto &controller = controllers.back;
if (controller.feedbackValid)
{
doc["bbv"] = controller.getCalibratedVoltage();
// Amperes
doc["bla"] = fixCurrent(controller.feedback.left.dcLink);
doc["bra"] = fixCurrent(controller.feedback.right.dcLink);
// Temperature
doc["bbt"] = fixBoardTemp(controller.feedback.boardTemp);
// Errors
doc["ble"] = controller.feedback.left.error;
doc["bre"] = controller.feedback.right.error;
// Speed
doc["bls"] = convertToKmh(controller.feedback.left.speed) * (controller.invertLeft?-1:1);
doc["brs"] = convertToKmh(controller.feedback.right.speed) * (controller.invertRight?-1:1);
}
else
{
return std::nullopt;
}
break;
}
}
// Statistics
if(avgVoltage)
// if empty, return empty string
if (doc.isNull())
{
doc["bP"] = getBatteryPercentage(*avgVoltage, BatteryCellType(configs.battery.cellType.value()));
doc["bV"] = *avgVoltage;
return std::nullopt;
}
doc["l"] = isLocked;
doc["mN"] = drivingStatistics.meters_driven;
doc["mT"] = drivingStatistics.totalMeters;
doc["dT"] = drivingStatistics.currentDrivingTime / 1ms;
doc["cW"] = watt;
doc["wN"] = drivingStatistics.wh_used;
doc["wL"] = getRemainingWattHours();
doc["kmL"] = getRemainingWattHours() / configs.battery.watthoursPerKilometer.value();
doc["ver"] = version_string.substr(0, 6);
doc["__t"] = configs.udpCloudSettings.udpToken.value();
std::string buf;
serializeJson(doc, buf);
return buf;
}
@ -145,7 +171,7 @@ void sendUdpCloudPacket()
return;
}
if (configs.udpCloudHost.value().empty())
if (configs.udpCloudSettings.udpCloudHost.value().empty() || configs.udpCloudSettings.udpCloudPort.value() == 0)
{
visualSendUdpPacket = false;
return;
@ -157,15 +183,15 @@ void sendUdpCloudPacket()
return;
}
if(espchrono::ago(lastSend) / 1000ms > configs.boardcomputerHardware.timersSettings.udpSendRateMs.value())
if(espchrono::ago(lastSend) / 1ms > configs.boardcomputerHardware.timersSettings.udpSendRateMs.value())
{
lastSend = espchrono::millis_clock::now();
ip_addr_t udpCloudIp;
if (const auto res = dns_gethostbyname(configs.udpCloudHost.value().c_str(), &udpCloudIp, nullptr, nullptr); res != ERR_OK)
if (const auto res = dns_gethostbyname(configs.udpCloudSettings.udpCloudHost.value().c_str(), &udpCloudIp, nullptr, nullptr); res != ERR_OK)
{
ESP_LOGE(TAG, "dns_gethostbyname() failed because: %i", res);
ESP_LOGE(TAG, "dns_gethostbyname() failed because: (%s) (%i)", lwip_strerr(res), res);
timestampLastFailed = espchrono::millis_clock::now();
visualSendUdpPacket = false;
return;
@ -180,12 +206,21 @@ void sendUdpCloudPacket()
}
sockaddr_in receipient;
receipient.sin_port = htons(24242);
receipient.sin_port = htons(configs.udpCloudSettings.udpCloudPort.value());
receipient.sin_addr.s_addr = udpCloudIp.u_addr.ip4.addr;
receipient.sin_family = AF_INET;
wifi_stack::UdpSender udpCloudSender;
const auto buf = buildUdpCloudJson();
std::string buf;
if (const auto json = buildUdpCloudJson(); !json)
{
return;
}
else
{
buf = *json;
}
if (const auto result = udpCloudSender.send(receipient, buf); !result)
{
@ -193,7 +228,7 @@ void sendUdpCloudPacket()
ESP_LOGE(TAG, "send to cloud failed: %.*s (ip=%s)", result.error().size(), result.error().data(), wifi_stack::toString(udpCloudIp.u_addr.ip4).c_str());
}
ESP_LOGI(TAG, "%s", buf.c_str());
// ESP_LOGI(TAG, "%s", buf.c_str());
visualSendUdpPacket = !visualSendUdpPacket;
}

View File

@ -1,6 +1,7 @@
#pragma once
// system includes
#include <optional>
#include <string>
// Little "flash" on statusdisplay when udp stuff is happening
@ -9,7 +10,5 @@ extern bool visualSendUdpPacket;
void udpCloudInit();
void udpCloudUpdate();
void spamUdpBroadcast();
std::string buildUdpCloudJson();
std::string buildUdpCloudString();
std::optional<std::string> buildUdpCloudJson();
void sendUdpCloudPacket();