Browse Source

renamed some functions for better presentability of their functionality mean

master
parent
commit
a0c51dcf12
  1. 25
      src/main.cpp

25
src/main.cpp

@ -9,6 +9,9 @@
#include "CpuLoad.h" #include "CpuLoad.h"
#define WEBSOCKETS_SERVER_CLIENT_MAX (20)
const char *ssid = "LabWork_1"; const char *ssid = "LabWork_1";
ESP8266WebServer server(80); ESP8266WebServer server(80);
@ -25,7 +28,7 @@ int accMax2 = 0;
WebSocketsServer webSocket = WebSocketsServer(81); WebSocketsServer webSocket = WebSocketsServer(81);
void handleAccelerometer() void handleMainPage()
{ {
int16_t bias = 0; int16_t bias = 0;
const int arr_size = 5000; const int arr_size = 5000;
@ -33,16 +36,13 @@ void handleAccelerometer()
memset(html_code, '\0', sizeof(char) * arr_size); memset(html_code, '\0', sizeof(char) * arr_size);
bias += getHtml(HTML_BEGIN, *html_code, arr_size, 0); bias += getHtml(HTML_BEGIN, *html_code, arr_size, 0);
// bias += getHtml(STYLE, *html_code, arr_size, bias);
// bias += getHtml(SCRIPT, *html_code, arr_size, bias);
// bias += getHtml(HTML_END, *html_code, arr_size, bias);
server.send(200, "text/html", html_code); server.send(200, "text/html", html_code);
delete[] html_code; delete[] html_code;
} }
void cookAccelerometer(String &in, int *in_array, int array_size) { void cookDataToJson(String &in, int *in_array, int array_size) {
String *output = ∈ String *output = ∈
int *array = in_array; int *array = in_array;
DynamicJsonBuffer jsonBuffer; DynamicJsonBuffer jsonBuffer;
@ -58,7 +58,7 @@ int lowFreqFilter(int inputValue, int lastFilteredValue, int alpha) {
return (lastFilteredValue + alpha * (inputValue - lastFilteredValue)+100); return (lastFilteredValue + alpha * (inputValue - lastFilteredValue)+100);
} }
void updateAccelerometer() void updateSensors()
{ {
if ((millis() - accelerometer.lastUpdate) > (1000 / graphAcc.updateRate)) if ((millis() - accelerometer.lastUpdate) > (1000 / graphAcc.updateRate))
{ {
@ -109,14 +109,14 @@ void handleNotFound()
server.send(404, "text/plain", message); server.send(404, "text/plain", message);
} }
void sendAccelerometerData() { void sendDataToSocket() {
int updateRate = 0; int updateRate = 0;
updateRate = 50; updateRate = 50;
if (millis() - lastDataSend > updateRate) { if (millis() - lastDataSend > updateRate) {
String word; String word;
cookAccelerometer(word, graphAcc.array, graphAcc.size); cookDataToJson(word, graphAcc.array, graphAcc.size);
webSocket.broadcastTXT(word); webSocket.broadcastTXT(word);
lastDataSend = millis(); lastDataSend = millis();
} }
@ -147,10 +147,7 @@ void setup(void)
Serial.print("AP IP address: "); Serial.print("AP IP address: ");
Serial.println(myIP); Serial.println(myIP);
server.on("/accelerometer", handleAccelerometer); server.on("/", handleMainPage);
server.on("/", []() {
server.send(200, "text/html", "<a style=\"font-size:10em;2\"href=\"http://192.168.1.1/accelerometer\">Main Page</a>");
});
server.onNotFound(handleNotFound); server.onNotFound(handleNotFound);
server.begin(); server.begin();
@ -168,8 +165,8 @@ void loop(void)
server.handleClient(); server.handleClient();
webSocket.loop(); webSocket.loop();
updateAccelerometer(); updateSensors();
sendAccelerometerData(); sendDataToSocket();
updateCpuTime(1); updateCpuTime(1);
printCpuLoad(); printCpuLoad();

Loading…
Cancel
Save