-->
Page 1 of 1

Shoody xml library esp 8266 also gives an error.

PostPosted: Sun Mar 11, 2018 1:11 am
by msuphi
hello.shoddy xml library is giving an error.Arduino IDE library shows that it is not suitable for esp 8266 and wiritten for esp 32. I can make it suitable for shoddy xml library esp8266.I am waiting for your help.It can be made compatible with esp 8266.
note: I'm doing an rss reader. But for the oled 128X32 screen, I have ESP 8266.
SHOODY XML LÄ°BRARY:
https://github.com/garretlab/shoddyxml/tree/master/src
My project:

Code: Select all#include <Adafruit_SSD1306.h>
#include <SPI.h>
#include <Wire.h>
#define OLED_RESET 2
Adafruit_SSD1306 display(OLED_RESET);

#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>

//#include "SO2002A_I2C.h"

//#include <WiFi.h>//FOR ESP 32
//#include <WiFiMulti.h>//FOR ESP 32
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFi.h>

#include <ESP8266HTTPClient.h>
//#include <HTTPClient.h>FOR ESP 32

#include "shoddyxml.h"

#define DISPLAY_WIDTH 128
#define DISPLAY_HEIGHT 32

const char *ssid = "msd";
const char *password = "CFPGawXk";
const struct site_t {
  char *title;
  char *url;
  char *contentsToDisplay;
} sites[] = {
  {"CNN.com", "http://rss.cnn.com/rss/edition.rss", "title"},
  {"BBC News", "http://feeds.bbci.co.uk/news/rss.xml", "description"},
};
const int delayPerCharacter = 200;
const int delayPerArticle = 1000;
const int delayPerRSS = 10000;
const char label = 0xfc;

int itemDepth = 0;
int lastTagMatches = 0;
char displayBuffer[DISPLAY_WIDTH + 1];
char *contentsToDisplay;

int httpGetChar();

//WiFiMulti wifiMulti; //FOR ESP 32
ESP8266WiFiMulti wifiMulti;
HTTPClient http;

WiFiClient *stream;
//SO2002A_I2C oled(0x3c);

shoddyxml x(httpGetChar);

void clearDisplayBuffer() {
  for (int i = 0; i < DISPLAY_WIDTH + 1; i++) {
    displayBuffer[i] = ' ';
  }
  displayBuffer[DISPLAY_WIDTH - 1] = label;
}

void displayPutChar(char c) {
  displayBuffer[DISPLAY_WIDTH] = c;
  for (int i = 0; i < DISPLAY_WIDTH; i++) {
    displayBuffer[i] = displayBuffer[i + 1];
  }
}

void printDisplayBuffer() {
  for (int i = 0; i < DISPLAY_WIDTH; i++) {
    display.setCursor(i, 1);
    display.print(displayBuffer[i]);
  }
}

void foundXMLDeclOrEnd() {

}

void foundPI(char *s) {

}

void foundSTag(char *s, int numAttributes, attribute_t attributes[]) {
  if (strcmp(s, "item") == 0) {
    itemDepth++;
  }

  if (strcmp(s, contentsToDisplay) == 0) {
    lastTagMatches = 1;
  } else {
    lastTagMatches = 0;
  }
}

void foundETag(char *s) {
  if ((itemDepth == 1) && (strcmp(s, contentsToDisplay) == 0)) {
    for (int i = 0; i < DISPLAY_WIDTH; i++) {
      displayPutChar(' ');
      printDisplayBuffer();
      delay(delayPerCharacter);
    }

    clearDisplayBuffer();
    delay(delayPerArticle);
  }
  if (strcmp(s, "item") == 0) {
    itemDepth--;
  }
}

void foundEmptyElemTag(char *s, int numAttributes, attribute_t attributes[]) {

}

void foundCharacter(char c) {
  if ((itemDepth == 1) && (lastTagMatches == 1)) {
    displayPutChar(c);
    printDisplayBuffer();
    delay(200);
  }
}

void foundElement(char *s) {

}

int httpGetChar() {
  if (http.connected()) {
    if (stream->available()) {
      return stream->read();
    } else {
      return 0;
    }
  }
  return EOF;
}

void setup() {
  // put your setup code here, to run once:
  //oled.begin(DISPLAY_WIDTH, DISPLAY_HEIGHT);
  //oled.clear();
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
    display.display();
  display.clearDisplay();

  /*
    WiFi.mode(WIFI_STA);
    WiFi.disconnect();
  */

  wifiMulti.addAP(ssid, password);

  clearDisplayBuffer();

  x.foundXMLDecl = foundXMLDeclOrEnd;
  x.foundXMLEnd = foundXMLDeclOrEnd;
  x.foundPI = foundPI;
  x.foundSTag = foundSTag;
  x.foundETag = foundETag;
  x.foundEmptyElemTag = foundEmptyElemTag;
  x.foundCharacter = foundCharacter;
  x.foundElement = foundElement;
}

void loop() {
  for (int i = 0; i < sizeof(sites) / sizeof(struct site_t); i++) {
    if ((wifiMulti.run() == WL_CONNECTED)) {
      itemDepth = 0;
      lastTagMatches = 0;

      //oled.clear();
        //display.clearDisplay();

      display.setCursor(0, 0);
      display.print(sites[i].title);
      display.display();
      contentsToDisplay = sites[i].contentsToDisplay;
      http.begin(sites[i].url);
      int httpCode = http.GET();
      if (httpCode > 0) {
        if (httpCode == HTTP_CODE_OK) {
          stream = http.getStreamPtr();
          x.parse();
        }
      }
      http.end();
      delay(delayPerRSS);
    } else {
      wifiMulti.addAP(ssid, password);
    }
  }
}