ESP8266 + Arduino = RSS
Posted:
Sun May 03, 2015 4:51 am
by Sanjay
Hi
Have anyone has done a esp8266 webclient that can read rss. I have code that does that through through arduino using Ethernet shield. i want to do the same with esp8266. can anyone help with this?
Re: ESP8266 + Arduino = RSS
Posted:
Sun May 03, 2015 8:09 am
by gerardwr
Please share the code, so we can have a look.
Re: ESP8266 + Arduino = RSS
Posted:
Mon May 11, 2015 10:49 pm
by Sanjay
Below is the code. I want to archive this using ESP8266 instead of Ethernet Shield
Code: Select all#include <Ethernet.h>
#include <TextFinder.h>
#include <SPI.h>
#include <string.h>
#include <Arduino.h>
#include <Wire.h>
#include <MicroLCD.h>
byte mac[] = {
0x90, 0xA2, 0xDA, 0x0D, 0x14, 0xBF }; //Ethernet Sheild MAC address
byte server[] = {
202,53,191,1 }; //Geonet IP
EthernetClient client;
TextFinder finder(client);
LCD_SSD1306 lcd; /* for SSD1306 OLED module */
String readbuffer = ""; //temp store previous reading
char readquake[100]; //string for incoming serial data
const int relay = 3; //pin number for relay
#define RELAY_ON 0 //relay ON
#define RELAY_OFF 1 //relay OFF
long TemppreviousMillis = 0; // will store last time temp was updated
long Tempinterval = 15000; // interval at which to relay turns OFF (milliseconds)
unsigned long currentMillis; // store time relay turns ON
String strMagnitude = "";
String strDay = "";
String strNow = "";
String strLocation = "";
String strTime = "";
String strDate = "";
String strIntensity = "";
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac);
lcd.begin();
//Initialize Pins so relays are inactive at reset
digitalWrite(relay, RELAY_OFF);
//set relay pins as ouputs
pinMode(relay, OUTPUT);
}
void loop()
{
if (client.connect(server,80)) //connect to Geonet server on port 80
{
client.println("GET /quakes/services/all.rss"); //connect to geonet rss
client.println("Host:beta.geonet.org.nz");
client.println("Connection: close");
client.println();
}
else
{
Serial.println("connection failed");
}
if (client.connected()) //when connected grab the data
{
if(finder.find("<title>")) //find word 'title' on rss
{
finder.getString("Magnitude", "<", readquake, (100)); //find word 'magnitute' the read 100 characters till character '<' is found.
if (String(readquake) != readbuffer) { //if read is new then print and turn ON relay
Serial.print("Magnitude ");
Serial.println(readquake);
readbuffer = String(readquake);
int magnitude = readbuffer.indexOf(',');
int day = readbuffer.indexOf(',', magnitude + 1);
int now = readbuffer.indexOf(',', day + 1);
int location = readbuffer.length();
//Serial.println(magnitude);
strMagnitude = readbuffer.substring(1,magnitude);
//Serial.println(strMagnitude);
//Serial.println(day);
strDay = readbuffer.substring(magnitude + 2,day);
//Serial.println(strDay);
//Serial.println(now);
strNow = readbuffer.substring(day + 2 ,now);
//Serial.println(strNow);
//Serial.println(location);
strLocation = readbuffer.substring(now + 2,location);
//Serial.println(strLocation);
int date = strNow.indexOf("at");
//Serial.println(date);
strDate = strNow.substring(0,date);
strTime = strNow.substring(date + 3, strNow.length() - 6);
//Serial.println(strDate);
//Serial.println(strTime);
MMintensity(strMagnitude);
OLEDDisplay();
//turn the relay ON
digitalWrite(relay, RELAY_ON);
TemppreviousMillis = currentMillis;// save the last time relay was turned ON
}
relayOFF(); //turn relay OFF
}
else
Serial.print("Could not find condition field");
}
else
{
Serial.println("Disconnected");
}
client.stop(); //clear buffer
client.flush();
delay(10000); //wait 10 sec before checking rss again.
}
//Function to turn OFF relay
void relayOFF() {
currentMillis = millis();
if(currentMillis - TemppreviousMillis > Tempinterval) //wait set interval time before turning off relay
{
digitalWrite(relay, RELAY_OFF);
}
}
void MMintensity(String MM){
char carray[MM.length() + 1];
MM.toCharArray(carray,sizeof(carray));
if (atof(carray) < 3)
{
strIntensity = "Unnoticeable" ;
} else if (
atof(carray) <= 4){
strIntensity = "Weak" ;
} else if (
atof(carray) <= 5){
strIntensity = "Light" ;
} else if (
atof(carray) <= 6){
strIntensity = "Moderate" ;
} else if (
atof(carray) <= 7){
strIntensity = "Strong" ;
} else if (
atof(carray) > 7){
strIntensity = "Severe" ;
}
//Serial.println(strIntensity);
}
void OLEDDisplay() {
lcd.clear();
lcd.setFontSize(FONT_SIZE_SMALL);
lcd.print("MM:");
lcd.setFontSize(FONT_SIZE_MEDIUM);
lcd.print(strMagnitude);
lcd.setFontSize(FONT_SIZE_SMALL);
lcd.setCursor(65,0);
lcd.println(strTime);
lcd.setCursor(60,1);
lcd.println(strDate);
lcd.setCursor(0,3);
lcd.print("LN:");
lcd.setCursor(20,3);
lcd.println(strLocation);
lcd.setCursor(0,6);
lcd.setFontSize(FONT_SIZE_MEDIUM);
lcd.println(strIntensity);
delay(1000);
}
Re: ESP8266 + Arduino = RSS
Posted:
Wed Jun 01, 2016 3:30 am
by varind
I've done something like this. It uses the ESP8266 to get RSS/XML/HTML data, then sends it to an Arduino by serial to be displayed on an LCD. The project is here:
http://www.variableindustries.com/web-to-lcd/