I managed to write smth that is sort of working. It works as intended, but core restarted in less then hour running this code.
Can someone take a look, maybe there are some obvious errors from my part?
[code]// 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 long check = 0;
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(60, 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/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;
}
//digitalClockDisplay();
//Serial.println();
Alarm.delay(0);
}
void Repeats(){
// Serial.println();
//Serial.println(“Application>\tStart of Loop.”);
// Request path and body can be set at runtime or at setup.
request.hostname = “api.thingspeak.com”;
request.port = 80;
request.path = “/channels/24877/fields/1/last.json?key=GOKBGDF6332V45P3”;
// The library also supports sending a body with your request:
//request.body = "{\"key\":\"value\"}";
// Get request
http.get(request, response, headers);
//Serial.print("Application>\tResponse status: ");
//Serial.println(response.status);
if(response.status == 200){
Serial.print("Application>\tHTTP Response Body: ");
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());
// Serial.println(timeStr);
update = 1;
}
}
void MidnightAlarm(){
minTemp = hetkeTemp;
maxTemp = hetkeTemp;
Spark.syncTime();
}[/code]
Fault is most likely in repeats() imo.