Verbos Bloom

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

#include "SoftwareSerial.h" esp.println(getRequest.

length() );

String ssid = "YOUR_SSID"; delay(500);


String password = "YOUR_WIFI_PASSWORD";
if (esp.find(">")) {
SoftwareSerial esp(3, 2);// RX, TX Serial.println("Sending..");
esp.print(getRequest);
String server = "www.iotboys.com"//YOUR_MIDDLE_WARE;
String uri = "/api/FacebookAutomation/ProcessCommand";//YOUR MIDDLE WARE if ( esp.find("SEND OK")) {
URI
Serial.println("Packet sent");
int RED_BULB = 5;
int YELLOW_BULB = 6; while (esp.available()) {

void setup() { String response = esp.readString();

pinMode(RED_BULB, OUTPUT); Serial.println(response);


pinMode(YELLOW_BULB, OUTPUT);
if (response.indexOf("RED BULB ON") > 0)
digitalWrite(RED_BULB, HIGH); {
digitalWrite(YELLOW_BULB, HIGH); digitalWrite(RED_BULB, LOW);
esp.begin(9600); }
else if (response.indexOf("RED BULB OFF") > 0)
Serial.begin(9600); {
digitalWrite(RED_BULB, HIGH);
connectWifi(); }
else if (response.indexOf("YELLOW BULB ON") > 0)
httpget(); {
digitalWrite(YELLOW_BULB, LOW);
delay(1000); }
else if (response.indexOf("YELLOW BULB OFF") > 0)
} {
void connectWifi() { digitalWrite(YELLOW_BULB, HIGH);
}
String cmd = "AT+CWJAP=\"" + ssid + "\",\"" + password + "\""; else if (response.indexOf("ALL ON") > 0)
{
esp.println(cmd); digitalWrite(RED_BULB, LOW);
digitalWrite(YELLOW_BULB, LOW);
delay(4000); }
else if (response.indexOf("ALL OFF") > 0)
if (esp.find("OK")) { {
digitalWrite(RED_BULB, HIGH);
Serial.println("Connected!"); digitalWrite(YELLOW_BULB, HIGH);
}
}
}
else { // close the connection
esp.println("AT+CIPCLOSE");
connectWifi();
}
Serial.println("Cannot connect to wifi"); }
} }

} void loop() {
/////////////////////////////GET METHOD/////////////////////////////// httpget();
}
void httpget() {
esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");//start a TCP connection.

if ( esp.find("OK")) {

Serial.println("TCP connection ready");

} delay(1000);

String getRequest =
"GET " + uri + " HTTP/1.0\r\n" +
"Host: " + server + "\r\n" +
"Accept: *" + "/" + "*\r\n" +
"Content-Type: application/json\r\n" +
"\r\n";

String sendCmd = "AT+CIPSEND=";//determine the number of caracters to be sent.

esp.print(sendCmd);

You might also like