I’ve kinda gave up on Spark Subscribe/publish and thought to try to upload to Thingspeak website with Core 1 and read from there with Core 2.
Core that is reading and displaying data randomly restarts, best i’ve had is 12h uptime. It bothers me because Min/Max temps of last 24h won’t be displayed properly. I only get readings since last restart.
My code is following:
// This #include statement was automatically added by the Spark IDE.
#include "HttpClient/HttpClient.h"
// This #include statement was automatically added by the Spark IDE.
#include "TimeAlarms/TimeAlarms.h"
// This #include statement was automatically added by the Spark IDE.
#include "Adafruit_mfGFX/Adafruit_mfGFX.h"
// This #include statement was automatically added by the Spark IDE.
#include "Adafruit_ILI9341/Adafruit_ILI9341.h"
//char displayText[64];
Adafruit_ILI9341 tft = Adafruit_ILI9341(A2, A1, A0);
float minTemp = 100;
float maxTemp = -100;
float hetkeTemp = 0;
int update = 0;
//int i=0;
String timeStr;
String timeMax;
String timeMin;
unsigned int uptime = 0;
HttpClient http;
// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
{ "Content-Type", "application/json" },
// { "Accept" , "application/json" },
{ "Accept" , "*/*"},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
void setup() {
Time.zone(+2);
Alarm.alarmRepeat(01,00,00, MidnightAlarm);
Alarm.timerRepeat(10, Repeats);
// Serial.begin(9600);
tft.begin();
tft.fillScreen(ILI9341_WHITE);
}
void loop() {
if(hetkeTemp>-40 && hetkeTemp <50 && update == 1){
if (minTemp>hetkeTemp){
minTemp=hetkeTemp;
timeMin = "";
if(Time.hour()<10){timeMin +=" ";}
timeMin += Time.hour();
timeMin += ":";
if(Time.minute()<10){timeMin +="0";}
timeMin += Time.minute();
}
if (maxTemp<hetkeTemp){
maxTemp=hetkeTemp;
timeMax = "";
if(Time.hour()<10){timeMax +=" ";}
timeMax += Time.hour();
timeMax += ":";
if(Time.minute()<10){timeMax +="0";}
timeMax += Time.minute();
}
uptime=millis()/1000/60;
tft.setRotation(1);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(160,3);
tft.print(uptime);
tft.setTextSize(8);
tft.setCursor(40,30);
if(hetkeTemp>0){tft.print("+");}
tft.print(hetkeTemp,1);
tft.setTextSize(3);
tft.setCursor(40,120);
tft.print("MAX ");
tft.setTextSize(2);
tft.setCursor(40,145);
tft.print(timeMax);
tft.setCursor(150,120);
tft.setTextSize(5);
if(maxTemp>0){tft.print("+");}
tft.print(maxTemp,1);
tft.setTextSize(3);
tft.setCursor(40,170);
tft.print("MIN ");
tft.setTextSize(2);
tft.setCursor(40,195);
tft.print(timeMin);
tft.setCursor(150,170);
tft.setTextSize(5);
if(minTemp>0){tft.print("+");}
tft.print(minTemp,1);
tft.setTextSize(2);
tft.setCursor(110,222);
tft.print(timeStr);
update = 0;
}
Alarm.delay(0);
}
void Repeats(){
request.hostname = "api.thingspeak.com";
request.port = 80;
request.path = "/channels/24877/fields/1/last.json?key=GOKBGDF6332V45P3";
http.get(request, response, headers);
if(response.status == 200){
String web = response.body;
String aeg2 = web.substring(28,34);
String aeg1 = web.substring(26,28);
int gmt = atof(aeg1.c_str());
int tund = gmt + 2;
timeStr = "";
timeStr += tund;
timeStr += aeg2;
timeStr += "";
int last = web.lastIndexOf('"');
int previous = web.lastIndexOf('"', last - 1 );
String result = web.substring(previous+1, last);
hetkeTemp = atof(result.c_str());
update = 1;
}
}
void MidnightAlarm(){
minTemp = hetkeTemp;
maxTemp = hetkeTemp;
Spark.syncTime();
}
Maybe i’m not using strings properly or doing smth wrong with http library?
I’d appreciate if you could point me into right direction.