-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScriptComparacionChar.ino
76 lines (71 loc) · 1.46 KB
/
ScriptComparacionChar.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "Arduino.h"
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
#include <NewPing.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeMono9pt7b.h>
#include <FS.h>
char stateNode[] = "t";
bool flagAlert1 = true;
char bufferP[200] = "";
void updateNodeState()
{
File testFile = SPIFFS.open(F("/node_state.txt"), "w");
if (testFile)
{
Serial.println("[dB] Write file content");
if (flagAlert1) {
sprintf(bufferP, "t\n");
} else
{
sprintf(bufferP, "f\n");
}
testFile.print(bufferP);
testFile.close();
}
else
{
Serial.println("[dB] Problem on create file");
}
}
void getNodeState()
{
File testFile = SPIFFS.open(F("/node_state.txt"), "r");
if (testFile)
{
Serial.println("[dB] Read file content 1");
sprintf(stateNode, "%s", testFile.readStringUntil('\n').c_str());
if (strcmp(stateNode, "t") == 0)
{
flagAlert1 = true;
}
else
{
flagAlert1 = false;
}
Serial.println("***********");
Serial.println(stateNode);
Serial.println("***********");
Serial.println(flagAlert1);
Serial.println("-----------");
testFile.close();
}
else
{
Serial.println("[dB] Problem on read state node file ");
}
}
void setup() {
Serial.begin(9600);
SPIFFS.begin();
Serial.println("Inicialize");
updateNodeState();
delay(3000);
getNodeState();
}
void loop() {
}