Last active
February 22, 2016 02:03
-
-
Save sabas1080/8eaea2f3184460a3f7b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
#include <SparkFunESP8266WiFi.h> | |
#include <avr/pgmspace.h> | |
#include <Servo.h> | |
#include <json_arduino.h> | |
#include "config.h" | |
Servo myservo; | |
ESP8266Client client; | |
char json_string[512]; | |
token_list_t *token_list = NULL; | |
// "{\"coord\":{\"lon\":-102.3,\"lat\":21.88},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"sky is clear\",\"icon\":\"02n\"}],\"base\":\"cmc stations\",\"main\":{\"temp\":5,\"pressure\":1025,\"humidity\":56,\"temp_min\":5,\"temp_max\":5},\"wind\":{\"speed\":7.7,\"deg\":20},\"clouds\":{\"all\":5},\"dt\":1453956180,\"sys\":{\"type\":1,\"id\":3966,\"message\":0.0026,\"country\":\"MX\",\"sunrise\":1453987717,\"sunset\":1454027754},\"id\":4019233,\"name\":\"Aguascalientes\",\"cod\":200}" | |
char* command; | |
String response; | |
bool begin = false; | |
void setup() | |
{ | |
int status; | |
Serial.begin(9600); | |
myservo.attach(3); // attaches the servo on pin 5 to the servo object | |
// To turn the MG2639 shield on, and verify communication | |
// always begin a sketch by calling cell.begin(). | |
status = esp8266.begin(); | |
if (status <= 0) | |
{ | |
Serial.println(F("Unable to communicate with shield. Looping")); | |
while(1) ; | |
} | |
esp8266.setMode(ESP8266_MODE_STA); // Set WiFi mode to station | |
if (esp8266.status() <= 0) // If we're not already connected | |
{ | |
if (esp8266.connect(mySSID, myPSK) < 0) | |
{ | |
Serial.println(F("Error connecting")); | |
while (1) ; | |
} | |
} | |
// Get our assigned IP address and print it: | |
Serial.print(F("My IP address is: ")); | |
Serial.println(esp8266.localIP()); | |
Serial.println(F("Press any key to post to IFTTT!")); | |
} | |
void loop() | |
{ | |
// If a character has been received over serial: | |
if (Serial.available()) | |
{ | |
// !!! Make sure we haven't posted recently | |
// Post to IFTTT! | |
getData(); | |
// Then clear the serial buffer: | |
while (Serial.available()) | |
Serial.read(); | |
} | |
} | |
void getData() | |
{ | |
if (client.connect(WEATHER_SERVER, HTTP_PORT) <= 0) | |
{ | |
Serial.println(F("Failed to connect to server.")); | |
return; | |
} | |
Serial.println(F("Connected.")); | |
client.print(F(HTTP_HEADER)); | |
// read response | |
// read response | |
while (client.available()) | |
Serial.write(client.read()); // read() gets the FIFO c | |
if (client.connected()) client.stop(); | |
Serial.println("close"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment