Created
January 3, 2021 14:17
-
-
Save sankarcheppali/9b27fd5d7904fe06fd460d9b9f5b72d7 to your computer and use it in GitHub Desktop.
website monitoring with WIO terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "TFT_eSPI.h" | |
#include "rpcWiFi.h" | |
#include "WiFiClientSecure.h" | |
#include "HTTPClient.h" | |
#include "ArduinoJson.h" | |
DynamicJsonDocument jsonResponse(1024); | |
const char *ssid = "m1Danger"; | |
const char *password = "abivarsh@2016"; | |
const String checkUrl = "https://api.freshping.io/v1/public-check-statuses/524828/"; | |
WiFiClientSecure wifiClient; | |
TFT_eSPI tft; | |
const char* caCert = "-----BEGIN CERTIFICATE-----\n" | |
"MIIEDzCCAvegAwIBAgIBADANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJVUzEl\n" | |
"MCMGA1UEChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMp\n" | |
"U3RhcmZpZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDQw\n" | |
"NjI5MTczOTE2WhcNMzQwNjI5MTczOTE2WjBoMQswCQYDVQQGEwJVUzElMCMGA1UE\n" | |
"ChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMpU3RhcmZp\n" | |
"ZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEgMA0GCSqGSIb3\n" | |
"DQEBAQUAA4IBDQAwggEIAoIBAQC3Msj+6XGmBIWtDBFk385N78gDGIc/oav7PKaf\n" | |
"8MOh2tTYbitTkPskpD6E8J7oX+zlJ0T1KKY/e97gKvDIr1MvnsoFAZMej2YcOadN\n" | |
"+lq2cwQlZut3f+dZxkqZJRRU6ybH838Z1TBwj6+wRir/resp7defqgSHo9T5iaU0\n" | |
"X9tDkYI22WY8sbi5gv2cOj4QyDvvBmVmepsZGD3/cVE8MC5fvj13c7JdBmzDI1aa\n" | |
"K4UmkhynArPkPw2vCHmCuDY96pzTNbO8acr1zJ3o/WSNF4Azbl5KXZnJHoe0nRrA\n" | |
"1W4TNSNe35tfPe/W93bC6j67eA0cQmdrBNj41tpvi/JEoAGrAgEDo4HFMIHCMB0G\n" | |
"A1UdDgQWBBS/X7fRzt0fhvRbVazc1xDCDqmI5zCBkgYDVR0jBIGKMIGHgBS/X7fR\n" | |
"zt0fhvRbVazc1xDCDqmI56FspGowaDELMAkGA1UEBhMCVVMxJTAjBgNVBAoTHFN0\n" | |
"YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAsTKVN0YXJmaWVsZCBD\n" | |
"bGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8w\n" | |
"DQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGsafPzWdqbAYcaT1epoXkJKtv3\n" | |
"L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLMPUxA2IGvd56D\n" | |
"eruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl\n" | |
"xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynp\n" | |
"VSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEY\n" | |
"WQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=\n" | |
"-----END CERTIFICATE-----\n"; | |
void setupLCD(){ | |
tft.begin(); | |
digitalWrite(LCD_BACKLIGHT, HIGH); // turn on the backlight | |
tft.setRotation(3); | |
tft.fillScreen(TFT_BLACK); //Black background | |
tft.setFreeFont(&FreeSansOblique12pt7b); //select Free, Sans, Oblique, 12pt. | |
} | |
void checkWiFi(){ | |
if(WiFi.status() == WL_CONNECTED){ | |
return; | |
} | |
int dotCounter = 0; | |
while (WiFi.status() != WL_CONNECTED) | |
{ | |
if(dotCounter%10 == 0){ | |
tft.fillScreen(TFT_BLACK); | |
tft.setCursor(100,110); | |
} | |
tft.print("."); | |
dotCounter ++; | |
WiFi.begin(ssid, password); | |
} | |
Serial.println(""); | |
Serial.println("WiFi connected"); | |
Serial.println("IP address: "); | |
Serial.println(WiFi.localIP()); | |
} | |
void setup() | |
{ | |
Serial.begin(115200); | |
delay(10); | |
Serial.println(); | |
Serial.print("Connecting to "); | |
Serial.println(ssid); | |
wifiClient.setCACert(caCert); | |
setupLCD(); | |
} | |
void loop(){ | |
checkWiFi(); | |
tft.fillScreen(TFT_BLACK); //Black background | |
tft.setCursor(0,20); | |
tft.println("Checking status..."); | |
HTTPClient client; | |
client.begin(wifiClient,checkUrl); // Make HTTP GET request | |
int httpCode = client.GET(); | |
tft.print("Request StatusCode: "); | |
tft.println(httpCode); | |
if(httpCode!=0){ | |
String jsonString = client.getString(); | |
Serial.println(jsonString); | |
deserializeJson(jsonResponse, jsonString); | |
const char *webSiteStatus = jsonResponse["state"]; | |
tft.print("Website state: "); | |
tft.println(webSiteStatus); | |
} | |
client.end(); | |
delay(10000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment