Sounak De
Published © GPL3+

BLYNKING webpage data using ThingSpeak and NodeMcu

A simple project to display a particular webpage data in blynk app via bluetooth module and using thingspeak platform.

BeginnerProtip45 minutes4,967
BLYNKING webpage data using ThingSpeak and NodeMcu

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Blynk
Blynk
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit diagram

Code

Weather Bot

Arduino
/*
 *  This sketch sends data via HTTP GET requests to data.sparkfun.com service.
 *
 *  You need to get streamId and privateKey at data.sparkfun.com and paste them
 *  below. Or just customize this script to talk to other HTTP servers.
 *
 */

#define BLYNK_PRINT Serial



    
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Your auth";

SoftwareSerial SerialBLE(D7,D8); // RX, TX

WidgetLCD lcd(V1);


#include <ESP8266WiFi.h>


const char* ssid     = "your wifi name";
const char* password = "password";

const char* host = "api.thingspeak.com";

int locate_text(String required, String bulk,int startpoint) {
  int foundpos = -1;
  if (bulk.length()<required.length())
    return foundpos;
  for (int i = startpoint; (i < bulk.length() - required.length()); i++) {
    if (bulk.substring(i,required.length()+i) == required) {
      foundpos = i;
      return foundpos;
    }
  }
  return foundpos;
}


void setup() {
  Serial.begin(9600);
  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);
  delay(10);

  // We start by connecting to a WiFi network

  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());
   lcd.clear();
  lcd.print(2, 0, "Weather"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  lcd.print(11, 1, "BOT");
}


void loop() {
  
  delay(10000);
  Blynk.run();
  lcd.clear();
  Serial.print("connecting to ");
  Serial.println(host);
  
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
  
  // We now create a URI for the request

  String url="/apps/thinghttp/send_request?api_key=your api key";
  Serial.print("Requesting URL: ");
  Serial.println(url);
  
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + 
               "Connection: close\r\n\r\n");
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client.stop();
      return;
    }
  }
  
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
// Serial.println(line);

 int initial_point= locate_text("large-temp",line,0);// my identifiers for required text...yours can be different

int final_point=locate_text("</",line,0);
int initial_point2= locate_text("cond",line,0);
int final_point2=locate_text("</",line,initial_point2+1);

   if (initial_point>0 && final_point>0)
{
  String y="";
  Serial.print("Temp:  ");
  lcd.print(0,1,"Temp:");
for (int i=initial_point+12;i<final_point-2;i++)
{
Serial.print(line[i]);
y=y+line[i];
}
lcd.print(6,1,y+" deg C");
}
Serial.println("");

if (initial_point2>0 && final_point2>0)
{ 
  Serial.print("Weather Condition: ");
  String t="";
for (int i=initial_point2+6;i<final_point2;i++)
{
  t=t+line[i];
Serial.print(line[i]);

}
lcd.print(0,0,t);
}

  }   
  
  
  Serial.println();
  Serial.println("closing connection");


}

Credits

Sounak De

Sounak De

0 projects • 12 followers
Hi,I am an undergrad passionate about electronics...both making and breaking them is a hobby.

Comments