반응형
Code
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
//==NodeMCU==START
#define D0 (16)
#define D1 (5) //SCL
#define D2 (4) //SDA
#define D3 (0)
#define D4 (2)
#define D5 (14)
#define D6 (12)
#define D7 (13)
#define D8 (15)
#define SD0 (7)
#define SD1 (8)
#define SD2 (9)
#define SD3 (10)
//==NodeMCU==END
//==WIFI==START
#include <ESP8266WiFi.h>
const char* ssid = "xxxx-xxx";
const char* password = "xxxxxxxxxx";
//==WIFI==END
//==LED BLINK==START
#define BUILTIN_LED D4
volatile bool statusLed = false;
//==LED BLINK==END
//==TIME_LOOP==START
#include <time.h>
#include <sys/time.h>
timeval tv;
int now_second;
void loop_time()
{
gettimeofday(&tv, nullptr);
static time_t lastv = 0;
if (lastv != tv.tv_sec) {
lastv = tv.tv_sec;
now_second = (lastv % 60);
}
}
//==TIME_LOOP==END
//==EEPROM==START
#include <EEPROM.h>
//----------------DOOR--------------
#define EEP_FIRST 1
#define EEP_SECOND 2
#define EEP_THIRD 3
//----------------DOOR DEFALT VALUE--------------
#define DE_EEP_FIRST 10
#define DE_EEP_SECOND 70
#define DE_EEP_THIRD 1
#define MAX_EEPROM 10
//==EEPROM==END
//==EEPROM==START
#define BUF_SIZE 500
char eepbuf[BUF_SIZE]; //EEPROM
char* eeprom_read(void)
{
char temp_buf[5];
int total_len=0;
memset(eepbuf,0,BUF_SIZE);
sprintf(eepbuf,"R_EEPROM {");
total_len = strlen(eepbuf);
for(int xx=0; xx< MAX_EEPROM; xx++)
{
memset(temp_buf,0,sizeof(temp_buf));
sprintf(temp_buf,"%d,",EEPROM.read(xx));
sprintf(eepbuf + total_len,"%s",temp_buf);
total_len = strlen(eepbuf);
}
sprintf(eepbuf + total_len,"}");
//Serial.println(spbuf);
return eepbuf;
}
#define DELAY_EEPROM_WRITE 1
void eeprom_init_zero(void)
{
for(int xx=0; xx< MAX_EEPROM; xx++)
{
EEPROM.write(xx, 0);
delay(DELAY_EEPROM_WRITE);
}
EEPROM.commit();
delay(DELAY_EEPROM_WRITE);
}
void eeprom_default_value_set()
{
//----------------WINDOW--------------
EEPROM.write(EEP_FIRST, DE_EEP_FIRST);
delay(DELAY_EEPROM_WRITE);
EEPROM.write(EEP_SECOND, DE_EEP_SECOND);
delay(DELAY_EEPROM_WRITE);
EEPROM.write(EEP_THIRD, DE_EEP_THIRD);
delay(DELAY_EEPROM_WRITE);
//----------------EEPROM commit--------------
EEPROM.commit();
delay(DELAY_EEPROM_WRITE);
}
//==EEPROM==END
void setup(void) {
Serial.begin(115200);
delay(3000);
//==WIFI==START
Serial.println("WIFI !");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("\nConnecting to "); Serial.println(ssid);
uint8_t i = 0;
while (WiFi.status() != WL_CONNECTED && i++ < 600) delay(500);
if(i == 601){
Serial.print("Could not connect to"); Serial.println(ssid);
while(1) delay(500);
}
else
{
Serial.print("\nConnected: "); Serial.println(ssid);
}
//==WIFI==END
//==EEPROM==START
EEPROM.begin(MAX_EEPROM);
Serial.println(eeprom_read());
char buf_temp[BUF_SIZE];
memset(buf_temp,0,BUF_SIZE);
if((EEPROM.read(1) == 0)&&((EEPROM.read(2) == 0)))
{
sprintf(buf_temp,"ESP8266 EEPROM initialization Start!\n");
eeprom_default_value_set();
}
else
{
sprintf(buf_temp,"ESP8266 Start!\n");
}
Serial.println(buf_temp);
Serial.println(eeprom_read());
//ESP.eraseConfig();
//==EEPROM==END
} //setup()
void loop(void) {
//==TIME_LOOP==START
loop_time();
//==TIME_LOOP==END
} //loop()
|
cs |
Result
Connecting to xxxx-xxx Connected: xxxx-xxx R_EEPROM {4,1,10,21,255,255,255,255,255,255,} ESP8266 Start! R_EEPROM {4,1,10,21,255,255,255,255,255,255,} |
'ESP8266' 카테고리의 다른 글
esp8266 - udp (send, receive) (0) | 2023.01.05 |
---|---|
esp8266 - multicast with python pc (0) | 2023.01.02 |
ESP8266 - lcd 20x4 with ntp (0) | 2023.01.02 |
esp8266 - lcd 16x2 and ntp (0) | 2023.01.02 |
esp8266 - i2c 주소 찾기 ( find i2c address) (0) | 2023.01.02 |