Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ArduinoJson.h>
- #include <EthernetServer.h>
- #include <Ethernet.h>
- #include <Dhcp.h>
- #include <EthernetClient.h>
- #include <EthernetUdp.h>
- #include <Dns.h>
- #include <SPI.h>
- #define RBUFFSIZE 600
- #include <TimeLib.h>
- #include <Time.h>
- #include <SevSeg.h>
- SevSeg sevseg;
- char* Buffer = malloc(4 * sizeof(char)); // array to hold the result
- int MIN;
- int HOR;
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- const char server[] = "api.openweathermap.org";
- // Set the static IP address to use if the DHCP fails to assign
- IPAddress ip(192,168,1,202);
- EthernetClient client;
- char responseBuffer[RBUFFSIZE];
- int rbindex = 0;
- boolean startCapture;
- void DrawClock() {
- time_t t = now();
- MIN= minute(t);
- char buf[2];
- sprintf (buf, "%04i", MIN);
- //as of now only prints minute
- //Serial.println(Buffer);
- sevseg.setChars( buf);
- sevseg.refreshDisplay();
- }
- int HitClient(){
- // start the Ethernet connection:
- if (Ethernet.begin(mac) == 0)
- {
- Serial.println("Failed to start Ethernet");
- Ethernet.begin(mac, ip);
- }
- // give the Ethernet shield a half-second to initialize:
- delay(500);
- Serial.println("Connecting...");
- // if you get a connection, report back via serial:
- if (client.connect(server, 80))
- {
- Serial.println("Connected!");
- const String html_cmd1 = "https://script.googleusercontent.com/macros/echo?user_content_key=PW95UwY2XPlsWCTOh6jzuRMgqIuaq9cNkMqicouqMXm8ephtrjBYGGUJP2M32Nw3jdorQm-cfz--S2d7P4gnNfygbqsEG9b-m5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx_ryfhECjZEnJ9GRkcRevgjTvo8Dc32iw_BLJPcPfRdVKhJT5HNzQuXEeN3QFwl2n0M6ZmO-h7C6bwVq0tbM60-_IQDS8gp7-x-dZ28mtWEA5GNj-qTZ_41&lib=MwxUjRcLr2qLlnVOLh12wSNkqcO1Ikdrk";
- // Make a HTTP request:
- client.println(html_cmd1);
- client.println();
- responseBuffer[0] = '\0';
- rbindex = 0;
- startCapture = false;
- }
- else
- {
- // if you didn't get a connection to the server:
- Serial.println("failed!");
- }
- if (client.available())
- {
- char c = client.read();
- if (c == '{') {
- startCapture = true;
- }
- if (startCapture && rbindex < RBUFFSIZE) {
- responseBuffer[rbindex] = c;
- rbindex++;
- }
- }
- // if the server's disconnected, stop the client:
- if (!client.connected()) {
- Serial.println(strlen(responseBuffer));
- client.stop();
- client.flush();
- Serial.println();
- StaticJsonBuffer<465> jsonBuffer;
- JsonObject& root = jsonBuffer.parseObject(responseBuffer);
- if (!root.success()) {
- Serial.println("failed");
- } else {
- Serial.println(root["hours"].as<String>()+":"+root["minutes"].as<String>());
- return(root["hours"].as<int>()*60*60)+(root["minutes"].as<int>()*60);//return hour and minute in seconds snce mdnght jan1 1970
- }
- }
- }
- void setup() {
- Serial.begin(9600);
- HitClient();
- setSyncProvider(HitClient());
- setSyncInterval(10000000);
- byte numDigits = 4;
- byte digitPins[] = {4, 1, 10, 8};
- byte segmentPins[] = {0, 2, 7, 6, 5, 3, 9, 12};
- bool resistorsOnSegments = true; // Use 'true' if on digit pins
- byte hardwareConfig = COMMON_ANODE; // See README.md for options
- sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
- }
- void loop() {
- DrawClock();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement