Showing posts with label esp8266 book. Show all posts
Showing posts with label esp8266 book. Show all posts

Sunday, September 23, 2018

ESP8266 Home Automation Projects - Errata

After the ESP8266 Home Automation Projects book was published, the wunderground.com service is not offering free services anymore, so the code presented in the Getting data from the internet part need to be reviewed.

There are two options in here: either you are subscribing to the wunderground.com service, paying a monthly subscription or you can choose other provider like OpenWeatherMap.org

Go to openweathermap.org an create an account. After login you will find your own API Key that will be used later in the code.

Now the code for getting current data is:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const String OPENWEATHERMAP_API_KEY = "YOUR_OPENWEATHERMAP_API_KEY";
const String OPENWEATHERMAP_COUNTRY = "us";
const String OPENWEATHERMAP_CITY = "New York";
const String dataURL = "http://api.openweathermap.org/data/2.5/weather?q="+OPENWEATHERMAP_CITY+","+OPENWEATHERMAP_COUNTRY+"&APPID="+OPENWEATHERMAP_API_KEY;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  delay(10);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println(dataURL);

  if(WiFi.status() == WL_CONNECTED)
  {
    HTTPClient http;
    http.begin(dataURL);
    int httpCode = http.GET();
    if(httpCode> 0) {
      // HTTP header has been send and Server response header has been handled
      Serial.printf("[HTTP] GET... code: %d\n", httpCode);
      // file found at server
      if(httpCode == HTTP_CODE_OK) {
        String payload = http.getString();
        Serial.println(payload);
      }
    }
  }
}

void loop() {
  // put your main code here, to run repeatedly:
}

To check if the formed link is working, get the output from:

Serial.println(dataURL);

and check it in a browser. You should see the response in JSON format. I encourage you to test the links first in browser and later on the ESP8266.


For more information on how to get data you can access the link: https://openweathermap.org/current

At this time the free account has:

OpenWeatherMap Free Account



If you need to get the data every minute you can use the following code:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const String OPENWEATHERMAP_API_KEY = "YOUR_OPENWEATHERMAP_API_KEY";
const String OPENWEATHERMAP_COUNTRY = "us";
const String OPENWEATHERMAP_CITY = "New York";
const String dataURL = "http://api.openweathermap.org/data/2.5/weather?q="+OPENWEATHERMAP_CITY+","+OPENWEATHERMAP_COUNTRY+"&APPID="+OPENWEATHERMAP_API_KEY;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  delay(10);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println(dataURL);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(WiFi.status() == WL_CONNECTED)
  {
    HTTPClient http;
    http.begin(dataURL);
    int httpCode = http.GET();
    if(httpCode> 0) {
      // HTTP header has been send and Server response header has been handled
      Serial.printf("[HTTP] GET... code: %d\n", httpCode);
      // file found at server
      if(httpCode == HTTP_CODE_OK) {
        String payload = http.getString();
        Serial.println(payload);
      }
    }

  }
delay(10*6000)
}

To make use of the results you will need to parse the JSON response and extract the data you need.



Thursday, December 21, 2017

Very good offer for books and videos from Packt Pub. On eBook $5

Packt Publishing has a new offer, for $5 you can get a lot of eBooks and videos.

Click here for a list. There are over 4000 books and over 1000 videos to choose from.


Saturday, December 2, 2017

New book on how to made a complete ready-to-sell home automated system with ESP8266

I've been busy in the latest months writing a book  to cover some key aspects of the ESP8266 ecosystem, the chip, the cloud and a mobile application.

The book will teach you and will give you a ready-to-sell solution for an IoT product.

You will discover how to work with the GPIOs on the ESP8266, how to build your basic thermostat for your house, how to control it from your mobile with your own cloud system based on MQTT.

Securing the data using authentication at the broker level and SSL is explained in a special chapter. 

Real-time communication has a dedicated chapter where you will learn how to send real-time data from an ESP8266 to an nodejs server.

You can buy the book from Amazon. 

I hope that you will enjoy the book.