mirror of
https://github.com/supleed2/ELEC50003-P1-CW.git
synced 2024-12-22 21:45:49 +00:00
Updated main to use portable Ticker Lib
This commit is contained in:
parent
99c3af355b
commit
0dee19f28c
|
@ -108,17 +108,11 @@
|
|||
var BTRY_VOLT = 0;
|
||||
var ODO_DIST = 0;
|
||||
|
||||
function round(value, precision) {
|
||||
var multiplier = Math.pow(10, precision || 0);
|
||||
return Math.round(value * multiplier) / multiplier;
|
||||
}
|
||||
|
||||
connection.onmessage = function (event) {
|
||||
var raw_data = event.data;
|
||||
console.log(raw_data);
|
||||
var data = JSON.parse(raw_data);
|
||||
digiBTRY_VOLT = data.BTRY_VOLT;
|
||||
BTRY_VOLT = round((digiBTRY_VOLT * (4.8e-4) + 4), 1)
|
||||
BTRY_VOLT = data.BTRY_VOLT;
|
||||
ODO_DIST = data.ODO_DIST;
|
||||
document.getElementById("btry_meter").value = BTRY_VOLT;
|
||||
document.getElementById("Odometer").innerHTML = ODO_DIST;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <AsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include <Ticker.h>
|
||||
#include "TickerV2.h"
|
||||
#include <WebSocketsServer.h>
|
||||
#include <credentials.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -27,10 +27,10 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t length)
|
|||
// Global objects
|
||||
AsyncWebServer webserver(80);
|
||||
WebSocketsServer websocketserver(81);
|
||||
Ticker ticker(returnSensorData, 500, 0, MILLIS);
|
||||
Ticker ticker;
|
||||
|
||||
// Global variables
|
||||
int battery_voltage = 0;
|
||||
float battery_voltage = 4.0f;
|
||||
int distance_travelled = 0;
|
||||
|
||||
void setup()
|
||||
|
@ -71,7 +71,7 @@ void setup()
|
|||
|
||||
websocketserver.begin();
|
||||
websocketserver.onEvent(webSocketEvent);
|
||||
ticker.start();
|
||||
ticker.attach(0.5, returnSensorData);
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -101,7 +101,17 @@ void printFPGAoutput()
|
|||
void returnSensorData()
|
||||
{
|
||||
// Collect sensor data here?
|
||||
distance_travelled++;
|
||||
if (battery_voltage < 6)
|
||||
{
|
||||
battery_voltage += 0.2;
|
||||
}
|
||||
else
|
||||
{
|
||||
battery_voltage = 4;
|
||||
}
|
||||
String JSON_Data = String("{\"BTRY_VOLT\":") + battery_voltage + String(",\"ODO_DIST\":") + distance_travelled + "}";
|
||||
Serial.println(JSON_Data);
|
||||
websocketserver.broadcastTXT(JSON_Data);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue