Here’s my current code:
[code]// This #include statement was automatically added by the Spark IDE.
#include “analogSmooth.h”
// This #include statement was automatically added by the Spark IDE.
#include “OneWire/OneWire.h”
// This #include statement was automatically added by the Spark IDE.
#include “LiquidCrystal_I2C.h”
#include “SparkTime/SparkTime.h”
String writeAPIKey = “xxx”;
String channelID = “20611”;
// TCP socket initialize
TCPClient client;
int ledRed = A0; //if ON then indicates that there is 230V present and boiler pump is OFF
int ledGreen = A1; // is ON then boiler pump is ON
int radikatemp = A2;
int toatemp = A3;
int pliiditemp = A4;
int pliidiveetemp = A5;
int relayRadiator = D2; //relay to turn ON/OFF radiator pump
int relayBoiler = D3; // relay to turn ON/OFF boiler pump.
int c = 0;
LiquidCrystal_I2C *lcd;
UDP UDPClient;
SparkTime rtc;
unsigned long currentTime;
unsigned long lastTime = 0UL;
String timeStr;
AnalogSmooth as100 = AnalogSmooth(100);
AnalogSmooth as101 = AnalogSmooth(100);
AnalogSmooth as102 = AnalogSmooth(100);
AnalogSmooth as103 = AnalogSmooth(100);
void setup(){
Serial.begin(9600);
Serial.println("===Starting===");
rtc.begin(&UDPClient, "north-america.pool.ntp.org");
rtc.setTimeZone(+2); // gmt offset
lcd = new LiquidCrystal_I2C(0x27, 20, 4); // set the LCD address to 0x20 for a 16x2 //SparkCore bug, address is actually 27 but shifted (0x27*2)
lcd->init(); // initialize the lcd
lcd->backlight();
lcd->clear();
pinMode(radikatemp, INPUT_PULLDOWN);
pinMode(toatemp, INPUT_PULLDOWN);
pinMode(pliiditemp, INPUT_PULLDOWN);
pinMode(pliidiveetemp, INPUT_PULLDOWN);
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(relayRadiator, OUTPUT);
pinMode(relayBoiler, OUTPUT);
digitalWrite(relayRadiator, LOW);
digitalWrite(relayBoiler, LOW);
analogWrite(ledRed,150);
}
void loop(){
currentTime = rtc.now();
if (currentTime != lastTime) {
timeStr = "";
timeStr += rtc.hour12String(currentTime);
timeStr += ":";
timeStr += rtc.minuteString(currentTime);
timeStr += ":";
timeStr += rtc.secondString(currentTime);
timeStr += " ";
timeStr += rtc.AMPMString(currentTime);
lastTime = currentTime;
}
lcd->setCursor(5,0);
lcd->print(timeStr);
double radikaC = (as100.analogReadSmooth(radikatemp) * 3.3) / 4095*100; //getting the voltage reading from the temperature sensor
double toaC = (as101.analogReadSmooth(toatemp) * 3.3) / 4095*100;
double pliidiC = (as102.analogReadSmooth(pliiditemp) * 3.3) / 4095*100;
// double pliidiveeC = (analogRead(pliidiveetemp) * 3.3) / 4095*100;
lcd->setCursor(1,1);
lcd->print("Radikasse");
lcd->setCursor(11,1);
lcd->print(radikaC, 1);
lcd->setCursor(1,2);
lcd->print("Toatemp");
lcd->setCursor(11,2);
lcd->print(toaC, 1);
lcd->setCursor(1,3);
lcd->print("Pliita");
lcd->setCursor(11,3);
lcd->print(pliidiC, 1);
c = tempkontroll(radikaC, toaC, c);
byte sec = rtc.second(currentTime);
if (sec == 10) {
if(Spark.connected())
{
ThingSpeakUpdate("field1="+String(toaC)+"&field2="+String(radikaC));
}
}
byte min = rtc.minute(currentTime);
if ((min == 10 && sec ==30) || (min == 20 && sec ==30) || (min == 30 && sec ==30) || (min == 40 && sec ==30) || (min == 50 && sec ==30) || (min == 01&& sec ==30)) {
lcd->init();
}
delay(1000);
}
void ThingSpeakUpdate(String tsData)
{
Serial.println("Date string: " + tsData);
Serial.println("...Connecting to Thingspeak");
// Connecting and sending data to Thingspeak
if(client.connect("api.thingspeak.com", 80))
{
Serial.println("...Connection succesful, updating datastreams");
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("\n\n");
client.println(tsData); //the ""ln" is important here.
// This delay is pivitol without it the TCP client will often close before the data is fully sent
delay(200);
Serial.println("Thingspeak update sent.");
}
else{
// Failed to connect to Thingspeak
Serial.println("Unable to connect to Thingspeak.");
}
if(!client.connected()){
client.stop();
}
client.flush();
client.stop();
}
int tempkontroll(double radikaC, double toaC, int c)
{
if(toaC < 21 && radikaC > 35 && c == 0) {
c = 1;
digitalWrite(relayRadiator, HIGH); //paneb relee "HIGH" asendisse
}
else if((toaC > 22 || radikaC < 35) && c == 1) {
c = 0;
digitalWrite(relayRadiator, LOW); //paneb relee "LOW" asendisse
}
return c;
}
[/code]
atm i added
byte min = rtc.minute(currentTime);
if ((min == 10 && sec ==30) || (min == 20 && sec ==30) || (min == 30 && sec ==30) || (min == 40 && sec ==30) || (min == 50 && sec ==30) || (min == 01&& sec ==30)) {
lcd->init();
}
that should do the trick but it’s not a solution.
ScruffR - yea id say bout 5x longer. What do you suggest me to try?