-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnodemcu_new.ino
149 lines (110 loc) · 4.37 KB
/
nodemcu_new.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
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
/**
* BasicHTTPClient.ino
*
* Created on: 24.05.2015
*
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;
//DEFINE ALL GLOBAL VAARIABLES HERE
String payload;
int l1=D0;
int l2=D1;
int l3=D2;
int l4=D3;
//keywords for EmaticX
const char keyword_html_start_b[] = "b>" ;
const char keyword_html_end_b[] = "</b>";
void cmd_read();
void setup() {
USE_SERIAL.begin(115200);
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush(); // Waits for the transmission of outgoing serial data to complete.
// clears the buffer once all outgoing characters have been sent.
delay(1000);
}
pinMode(l1, OUTPUT);
pinMode(l2, OUTPUT);
pinMode(l3, OUTPUT);
pinMode(l4, OUTPUT);
WiFiMulti.addAP("asus11", "youtube12");
}
void loop() {
// wait for WiFi connection
if((WiFiMulti.run() == WL_CONNECTED)) { //WL_CONNECTED: assigned when connected to a WiFi network //WiFi.status()
// WL_DISCONNECTED: assigned when disconnected from a network etc..
HTTPClient http;
USE_SERIAL.print("[HTTP] begin...\n");
// configure traged server and url
http.begin("https://nishantiitd.000webhostapp.com/file_to_read.html"); //HTTP
USE_SERIAL.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if(httpCode == HTTP_CODE_OK) { // For response code 200, we have the constant as HTTP_CODE_OK. & 404,is the error( Page not found )
payload = http.getString(); //To read the response message, we call http.getString(). This will return a string object.
// http request -- GET(),POST()
USE_SERIAL.println(payload);
}
} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
cmd_read();
delay(1000);
}
void cmd_read()
{
if(payload.indexOf("A1") >0) // Locates a character or String within another String. By default,
//searches from the beginning of the String, but can also start from a given index,
//allowing for the locating of all instances of the character or String
{Serial.println("l1one");
digitalWrite(l1, HIGH);}
if(payload.indexOf("B1") >0)
{Serial.println("l2one");
digitalWrite(l2, HIGH);}
if(payload.indexOf("C1") >0)
{Serial.println("l3one");
digitalWrite(l3, HIGH);}
if(payload.indexOf("D1") >0)
{Serial.println("l4one");
digitalWrite(l4, HIGH);}
if(payload.indexOf("A0") >0)
{Serial.println("l1off");
digitalWrite(l1, LOW);}
if(payload.indexOf("B0") >0)
{Serial.println("l2off");
digitalWrite(l2, LOW);}
if(payload.indexOf("C0") >0)
{Serial.println("l3off");
digitalWrite(l3, LOW);}
if(payload.indexOf("D0") >0)
{Serial.println("l4off");
digitalWrite(l4, LOW);}
/* if(strcmp(payload, "keyword_html_start_b[]") == 0){
Serial.println("Command received: LEDON");
// Esplora.writeRGB(255, 255, 255);
}else if (strcmp(payload, "0000") == 0) {
Serial.println("Command received: LEDOFF");
// Esplora.writeRGB(0, 0, 0);
}else{
Serial.println("Command received: unknown!");
}
}else{
if(cmdIndex++ >= MAX_CMD_LENGTH){
cmdIndex = 0;
}*/
}