Browse Source

Небольшие правки, не влияющие на работу

master
Defend 7 years ago
parent
commit
2b46a59988
  1. 40
      src/main.cpp

40
src/main.cpp

@ -7,32 +7,26 @@
#include <html.h>
const char *ssid = "NodeMCU";
const char *password = "kvartira138";
ESP8266WebServer server(80);
DHT12 dht12(5, true);
const int led = 13;
long int lastUpdate = 0;
int t12 = 0;
int h12 = 0;
int acc = 0;
const int graph_size = 200;
int graph1[graph_size] = { 200 };
int graph1counter = 0;
int graphUpdate = 50; // Раз в секунду
void handleRoot()
void handleAccelerometer()
{
int16_t bias = 0;
const int arr_size = 10000;
char *html_code = new char[arr_size];
memset(html_code, '\0', sizeof(char)*arr_size);
int16_t bias = 0;
int16_t bias2 = 0;
bias += getHtml(HTML_BEGIN, *html_code, arr_size, 0);
bias += getHtml(STYLE, *html_code, arr_size, bias);
bias += getHtml(SCRIPT_BEGIN, *html_code, arr_size, bias);
@ -40,26 +34,18 @@ void handleRoot()
bias += snprintf((html_code+bias), arr_size - bias, "context.lineTo(%i*2, %i);", i, graph1[i]);
}
bias += getHtml(SCRIPT_END, *html_code, arr_size, bias);
bias += snprintf(
(html_code+bias), arr_size - bias,
"<br> Current temperature: %i \
<br> Current humudity: %i \
<br />Current accelerometr: %i",
t12, h12, acc);
//bias += snprintf((html_code+bias), arr_size - bias, "<br />Current accelerometer: %i", acc);
bias += getHtml(HTML_END, *html_code, arr_size, bias);
server.send(200, "text/html", html_code);
delete[] html_code;
}
void updateDHT()
void updateAccelerometer()
{
if ((millis() - lastUpdate) > 20)
if ((millis() - lastUpdate) > (1000 / graphUpdate))
{
// t12 = (int)dht12.readTemperature();
// int t12_remapped = map(t12, -20, 100, 200, 0);
// h12 = (int)dht12.readHumidity();
acc = map(analogRead(A0), 512, 768, 200, 0);
if (graph1counter < graph_size - 1) {
graph1[graph1counter] = acc;
@ -101,12 +87,10 @@ void setup(void)
Serial.print("AP IP address: ");
Serial.println(myIP);
server.on("/", handleRoot);
server.on("/inline", []() {
server.send(200, "text/plain", "this works as well");
server.on("/accelerometer", handleAccelerometer);
server.on("/", []() {
server.send(200, "text/plain", "http://192.168.4.1/accelerometer");
});
server.onNotFound(handleNotFound);
server.begin();
@ -115,6 +99,6 @@ void setup(void)
void loop(void)
{
updateDHT();
updateAccelerometer();
server.handleClient();
}
Loading…
Cancel
Save