52 lines
1017 B
C++
52 lines
1017 B
C++
#pragma once
|
|
|
|
#include <Figments.h>
|
|
#include <JsonListener.h>
|
|
#include <JsonStreamingParser.h>
|
|
#include <WiFiClient.h>
|
|
|
|
class Weather : public BufferedInputSource, OnlineTaskMixin, JsonListener {
|
|
public:
|
|
Weather();
|
|
|
|
void handleEvent(const InputEvent& evt) override;
|
|
void loop() override;
|
|
|
|
void onOnline() override {
|
|
update();
|
|
}
|
|
|
|
void onStart() override {
|
|
update();
|
|
}
|
|
|
|
void loopOnline() override {
|
|
}
|
|
|
|
void update();
|
|
void parse();
|
|
|
|
virtual void whitespace(char c);
|
|
virtual void startDocument();
|
|
virtual void key(String key);
|
|
virtual void value(String value);
|
|
virtual void endArray();
|
|
virtual void endObject();
|
|
virtual void endDocument();
|
|
virtual void startArray();
|
|
virtual void startObject();
|
|
|
|
private:
|
|
JsonStreamingParser m_parser;
|
|
WiFiClient m_client;
|
|
bool m_fetching = false;
|
|
String m_curKey;
|
|
String m_curField;
|
|
bool m_foundBody = false;
|
|
|
|
int m_weatherId = 0;
|
|
|
|
void doWeatherEvent();
|
|
};
|
|
|