I figured this one out.
- I decided to go with a different API from Weather Underground because it's more accurate in my (Poland) location. This made the problem even worse ~47 kb per API request.
- And so i use the Temboo. Theire HTTP get service makes the API call, and theire output filter, gives Yun just the data I need.
Below you have the full code, I use right now.
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information, as described below
#include "LedControl.h"
//#include "dod_funkcje.h"
#define LDR 1
LedControl lc = LedControl(12, 11, 10, 1);
int state = 0; // 1 = nie pada, nie pada; 2 = pada, pada; 3 = nie pada, pada; 4 = pada, nie pada
int last_state = 0;
byte sstop[4] = {0x77, 0x77, 0x77, 0x00}; // pada
byte play[4] = {0x44, 0x66, 0x44, 0x00}; //nie pada
boolean Agata; //0 nie pada, 1 pada
boolean Jachu; //0 nie pada, 1 pada
unsigned long previousMillis = 0; // will store last time LED was updated
unsigned long interval = 600000; // 10 min
int num = 0;
void setup() {
Serial.begin(9600);
// For debugging, wait until the serial console is connected
delay(4000);
while (!Serial);
Bridge.begin();
pinMode(LDR, INPUT);
lc.shutdown(0, false);
/* Set the brightness to a medium values */
lc.setIntensity(0, 8);
/* and clear the display */
lc.clearDisplay(0);
}
void loop() {
if (analogRead(LDR) >= 100) {
unsigned long currentMillis = millis();
if ((state == 0) || (currentMillis - previousMillis >= interval)) {
previousMillis = currentMillis;
num = num + 1;
Serial.print("Running GetChoreo ");
Serial.println(num);
delay(100);
int pogoda1;
int pogoda2;
int pogoda3;
// int pogoda4;
// int pogoda5;
// int pogoda6;
int pogoda7;
int pogoda8;
int pogoda9;
TembooChoreo GetChoreo;
// Invoke the Temboo client
GetChoreo.begin();
// Set Temboo account credentials
GetChoreo.setAccountName(TEMBOO_ACCOUNT);
GetChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
GetChoreo.setAppKey(TEMBOO_APP_KEY);
// Set Choreo inputs
GetChoreo.addInput("Password", "<myPASSWORD>");
GetChoreo.addInput("Debug", "<myEMAILaddress>");
GetChoreo.addInput("URL", "http://api.wunderground.com/api/<myAPIkey>/hourly/q/PL/Poznan.json");
// Identify the Choreo to run
GetChoreo.setChoreo("/Library/Utilities/HTTP/Get");
// add an output filter to extract the date and time of the last report.
GetChoreo.addOutputFilter("fctcode1", "hourly_forecast[1]/fctcode", "Response");
GetChoreo.addOutputFilter("fctcode2", "hourly_forecast[2]/fctcode", "Response");
GetChoreo.addOutputFilter("fctcode3", "hourly_forecast[3]/fctcode", "Response");
// GetChoreo.addOutputFilter("fctcode4", "hourly_forecast[4]/fctcode", "Response");
// GetChoreo.addOutputFilter("fctcode5", "hourly_forecast[5]/fctcode", "Response");
// GetChoreo.addOutputFilter("fctcode6", "hourly_forecast[6]/fctcode", "Response");
GetChoreo.addOutputFilter("fctcode7", "hourly_forecast[7]/fctcode", "Response");
GetChoreo.addOutputFilter("fctcode8", "hourly_forecast[8]/fctcode", "Response");
GetChoreo.addOutputFilter("fctcode9", "hourly_forecast[9]/fctcode", "Response");
// Run the Choreo; when results are available, print them to serial
GetChoreo.run();
while (GetChoreo.available()) {
// read the name of the next output item
String name = GetChoreo.readStringUntil('\x1F');
name.trim(); // use “trim” to get rid of newlines
// read the value of the next output item
String data = GetChoreo.readStringUntil('\x1E');
data.trim(); // use “trim” to get rid of newlines
if (name == "fctcode1") {
pogoda1 = data.toInt();
} else if (name == "fctcode2") {
pogoda2 = data.toInt();
} else if (name == "fctcode3") {
pogoda3 = data.toInt();
} /*else if (name == "fctcode4") {
pogoda4 = data.toInt();
} else if (name == "fctcode5") {
pogoda5 = data.toInt();
} else if (name == "fctcode6") {
pogoda6 = data.toInt();
}*/else if (name == "fctcode7") {
pogoda7 = data.toInt();
} else if (name == "fctcode8") {
pogoda8 = data.toInt();
} else if (name == "fctcode9") {
pogoda9 = data.toInt();
} else if (name == "Error") {
state = 5;
}
}
GetChoreo.close();
if ( pogoda1 >= 10 || pogoda2 >= 10 || pogoda3 >= 10) { //sprawdzam w ciągu trzech godzin czy bedzie padać
Agata = 1;
}
else if ( pogoda1 < 10 || pogoda2 < 10 || pogoda3 < 10) {
Agata = 0;
}
if (pogoda7 >= 10 || pogoda8 >= 10 || pogoda9 >= 10) { //sprawdzam w ciągu trzech godzin czy bedzie padać
Jachu = 1;
} else if ( pogoda7 < 10 || pogoda8 < 10 || pogoda9 < 10) {
Jachu = 0;
}
Serial.print("W ciagu najbliższych trzech godzin: ");
Serial.println(Agata);
Serial.print("Od 6 do 9 godziny: ");
Serial.println(Jachu);
Serial.println("Waiting...");
}
if (state < 5) {
if (Agata == 0 && Jachu == 0) {
state = 1;
}
if (Agata == 1 && Jachu == 1) {
state = 2;
}
if (Agata == 0 && Jachu == 1) {
state = 3;
}
if (Agata == 1 && Jachu == 0) {
state = 4;
}
}
// zmieniamy wynik na matrycy
if (state != last_state) {
if (state == 1) {
sstatus(0, 0); //nie pada, nie pada
}
if (state == 2) {
sstatus(1, 1); // pada pada
}
if (state == 3) {
sstatus(0, 1); // nie pada, pada
}
if (state == 4) {
sstatus(1, 0); // pada, nie pada
}
if (state == 5) {
error(); //error
}
last_state = state;
}
delay(2000); // wait 2 seconds
} else if (analogRead(LDR) <= 25) {
cleanMatrix();
state = 0;
last_state = 1;
delay(1000);
}
}
void sstatus(boolean a, boolean b){
if (a == 0){
lc.setRow(0,0,play[0]);
lc.setRow(0,1,play[1]);
lc.setRow(0,2,play[2]);
lc.setRow(0,3,play[3]);
}
else if (a == 1){
lc.setRow(0,0,sstop[0]);
lc.setRow(0,1,sstop[1]);
lc.setRow(0,2,sstop[2]);
lc.setRow(0,3,sstop[3]);
}
if (b == 0){
lc.setRow(0,4,play[0]);
lc.setRow(0,5,play[1]);
lc.setRow(0,6,play[2]);
lc.setRow(0,7,play[3]);
}
else if (b == 1){
lc.setRow(0,4,sstop[0]);
lc.setRow(0,5,sstop[1]);
lc.setRow(0,6,sstop[2]);
lc.setRow(0,7,sstop[3]);
}
}
void error(){
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,1);
}
void cleanMatrix(){
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
}