I am writing a code for making digital pin to be HIGH by timer.
I have written with HTML and php, but it does not work during the HTML file is not opened.
How can I make timer function which works well?
Could you kindly help me to write a sample?
Thanks. I am trying to make the core access to JASONP.
I am beginner, but I hope I can complete it.
// This #include statement was automatically added by the Spark IDE.
#include "SparkTime.h"
UDP UDPClient;
SparkTime rtc;
unsigned long currentTime;
unsigned long lastTime = 0UL;
String timeStr;
void setup() {
rtc.begin(&UDPClient, "north-america.pool.ntp.org");
rtc.setTimeZone(7); // gmt offset. I am using Malaysian time now
Serial.begin(9600);
}
void loop() {
currentTime = rtc.now();
if (currentTime != lastTime) {
// Just the time in 12 hour format
timeStr = "";
timeStr += rtc.AMPMString(currentTime); // modified to show AM/PM here for better visibility
timeStr += rtc.hour12String(currentTime);
timeStr += ":";
timeStr += rtc.minuteString(currentTime);
timeStr += " ";
Serial.print(timeStr);
}
lastTime = currentTime;
}
You could enter your time on a web page and then on a button click script have it POST to the core via a Spark function when you hit a “start” button on the web page.
Does “15:00” in your example above mean 15 minutes and zero seconds or does it mean 15 hours and zero minutes or does it mean at 15:00 real-time, which we would call 3:00 pm in the US?
I have not seen your tutorial. I will try it now.
my 15:00 means 15:00 real time.
Your “Real Time Clock Library for Spark” code shows time as 12 hour clock. So I use 12 hour clock on the code.
I am making water pump switch timer which turns on on time. the time is set on website.
With my library, you have your choice of 12 or 24 hour time. Both are available.
uint8_t hour(uint32_t tnow); // this always returns 24-hour time as an integer 0-23
String hourString(uint32_t tnow); // use this method for 24-hour time Strings
String hour12String(uint32_t tnow); // use this one 12-hour US time Strings
It sounds like you want the core to do an HTTP GET request to server on the internet and parse the resulting JSONP string. You can do that! You will only have trouble if the response from the server that needs to be parsed is very long and you have memory problems on the core.
There is also an awesome JSON parser based on the JSMN library. It was used in the openweather project on another topic. You can find the library on my github.