2021-06-09 14:25:18 +00:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#define WebSocket 0
|
2021-06-13 17:26:00 +00:00
|
|
|
int state, totalTripDistance, currentHeading, current_x, current_y, signal_strength, lastCompletedCommand_id; // Info Control ==> Command
|
|
|
|
float batteryVoltage, batteryLevel, batteryCycles; // Info Control ==> Command
|
2021-06-13 20:24:38 +00:00
|
|
|
int command_id, mode, reqHeading, reqDistance, reqCharge, reqTime; // Info Command ==> Control
|
2021-06-12 22:04:01 +00:00
|
|
|
float reqSpeed; // Info Command ==> Control
|
2021-06-09 14:25:18 +00:00
|
|
|
|
|
|
|
void setup() {}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
DynamicJsonDocument rdoc(1024); // receive doc, not sure how big this needs to be
|
|
|
|
deserializeJson(rdoc, WebSocket); // Take JSON input from WebSocket
|
2021-06-12 20:00:55 +00:00
|
|
|
state = rdoc["st"]; // State: -1 = Error, 0 = Idle, 1 = Moving, 2 = Charging
|
2021-06-13 16:59:21 +00:00
|
|
|
batteryVoltage = rdoc["bV"];
|
|
|
|
batteryLevel = rdoc["bL"];
|
|
|
|
batteryCycles = rdoc["bC"];
|
2021-06-09 14:25:18 +00:00
|
|
|
totalTripDistance = rdoc["tD"];
|
|
|
|
currentHeading = rdoc["cH"];
|
|
|
|
current_x = rdoc["pos"][0];
|
|
|
|
current_y = rdoc["pos"][1];
|
|
|
|
signal_strength = rdoc["rssi"];
|
|
|
|
lastCompletedCommand_id = rdoc["LCCid"];
|
|
|
|
|
|
|
|
// ResetTelemetry / STOP / M 0 50 1 / C %
|
|
|
|
// [20] Heading: 0, Distance: 50, Speed: 1 / [20] Charging to: ??%
|
|
|
|
// {"Cid":20,"rH":0,}
|
|
|
|
|
|
|
|
DynamicJsonDocument tdoc(1024); // transmit doc, not sure how big this needs to be
|
|
|
|
tdoc["Cid"] = command_id;
|
|
|
|
tdoc["mode"] = mode; // Switch (mode):
|
|
|
|
// -1 = Add to queue, reset x/y/odometer (telemetry data)
|
|
|
|
// 0 = Stop immediately, clear command cache
|
|
|
|
// 1 = Normal movement command, added to end of command cache
|
|
|
|
// 2 = Normal charge command, results in no motion, added to end of command cache
|
2021-06-13 20:24:38 +00:00
|
|
|
// 3 = Pause command, wait for defined time in seconds, added to end of command cache
|
2021-06-09 14:25:18 +00:00
|
|
|
tdoc["rH"] = reqHeading;
|
|
|
|
tdoc["rD"] = reqDistance;
|
|
|
|
tdoc["rS"] = reqSpeed;
|
|
|
|
tdoc["rC"] = reqCharge;
|
2021-06-13 20:24:38 +00:00
|
|
|
tdoc["pSt"] = reqTime;
|
2021-06-09 14:25:18 +00:00
|
|
|
serializeJson(tdoc, WebSocket, WebSocket); // Build JSON and send on UART1
|
|
|
|
}
|