commit a3dcb139db51cdc5c873b062f9d0b45c519cfc99 Author: Arne van Iterson Date: Sun Feb 16 12:00:22 2020 +0100 First commit diff --git a/M5_ARNweb.ino b/M5_ARNweb.ino new file mode 100644 index 0000000..813bbe1 --- /dev/null +++ b/M5_ARNweb.ino @@ -0,0 +1,207 @@ +#include +#include +#include +#include + +// New instance of WifiJson, silent is false, it will log to the M5Stacks screen +WifiJson wifi(false); +HTTPClient http; +StaticJsonDocument<1000> data; +char *jsonRes; + +// 'ram', 15x10px +const unsigned char ram [] PROGMEM = { + 0xff, 0x7f, 0x01, 0x40, 0x6d, 0x5b, 0x6d, 0x5b, 0x6d, 0x5b, 0x6d, 0x5b, + 0x01, 0x40, 0xc1, 0x41, 0x55, 0x55, 0x7f, 0x7f +}; +// 'hdd', 14x12px +const unsigned char hdd[] = { + 0xfc, 0x0f, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x01, 0x20, + 0x01, 0x20, 0xff, 0x3f, 0x01, 0x20, 0x55, 0x29, 0x55, 0x21, 0xff, 0x3f +}; +// 'swap', 13x13px +const unsigned char swap [] PROGMEM = { + 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x1f, + 0xff, 0x10, 0xff, 0x10, 0x20, 0x10, 0x22, 0x10, 0x26, 0x10, 0x22, 0x10, + 0xe0, 0x1f +}; +// 'temp', 7x14px +const unsigned char temp [] PROGMEM = { + 0x1c, 0x36, 0x22, 0x22, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x49, 0x5d, 0x49, + 0x22, 0x1c +}; + +const char* ca = \ +"-----BEGIN CERTIFICATE-----\n" \ +"MIIFlTCCBH2gAwIBAgISA5tHKDD+RZnTEVnc4cB00DmoMA0GCSqGSIb3DQEBCwUA\n" \ +"MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD\n" \ +"ExpMZXQncyBFbmNye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gZngQwBAgEwNwYLKwYBBAGC3xMBAQEwKDAmBggrBgEF\n" \ +"BQcCARYaaHR0cDovL2Nwcy5sZXRzZW5jcnlwdC5vcmcwggEBBgorBgEEAdZ5AgQC\n" \ +"BIHyBIHvAO0AdADwlaRZ8gDRgkAQLS+TiI6tS/4dR+OZ4dA0prCoqo6ycwAAAXAD\n" \ +"9GbiAAAEAwBFMEMCHxM9P+xmvv54KfAnXPUi/ktr4y+71JT6J3SNK1btmoICIDj4\n" \ +"ixR9xXRdcpEEbXGiD2SNSYKo/smj1OOLVdxdl2OoAHUAsh4FzIuizYogTodm+Su5\n" \ +"iiUgZ2va+nDnsklTLe+LkF4AAAFwA/Rm1gAABAMARjBEAiApjqhGjDMeyUMi8QGa\n" \ +"OcM/D23MOxk5DrhAl4V3qHZHuwIgeBIpEQA8gnWTrbBXh5zk7OYQN9F7g1nHDeWq\n" \ +"Hx8VvPAwDQYJKoZIhvcNAQELBQADggEBACuCb/oAQM85nhAqhBZ2PvVduwQClbVF\n" \ +"3vhAXecoCzWNZfl7joCEjnQZyLdWtrmnK+EVZsAzyiK9/2e+dB8JC0xbO6KBb5/Y\n" \ +"uqwdtaq/nsjNa4UaUEIE2CDOUOYXptmMpq8zSpMSWGyKGABkTLDewrHK8mBaub5t\n" \ +"sBQyrdL6tlrzL5nsCmwrEgL83YZQUJWEuv5Egjf/D1xIjcv9CVp/1aG/dgBSCG9r\n" \ +"o0JzQTtjS2OybPs4QOXWWMo0yDVi20OVy85qIFNHLXAJPnZ9iUAa3gaqcUmtzdtS\n" \ +"pbTG+YNnvJ/ZtdWQSkqvkzY7siZ/Ze3RjhYRR+GPt+BLco7DkuZlPbE=\n" \ +"-----END CERTIFICATE-----\n"; + +void setup() { + M5.begin(); + + /* + Attempt connecting to a network using credentials in /wifi.json. + Will return false if connection fails + */ + if (!wifi.begin("/wifi.json")) + { + Serial.println("This program requires a WiFi connection!"); + M5.Lcd.println("This program requires a WiFi connection!"); + + // Do not let the program run + while (true) + { } + } + Serial.println(wifi.ip); + M5.Lcd.println(wifi.ip); + + delay(500); + update(); +} + +void update() { + M5.Lcd.fillScreen(0x1082); + M5.Lcd.setCursor(0,0); + + int httpCode = 0; + M5.Lcd.setTextSize(2); + + http.begin("https://api.arnweb.nl/system", ca); + httpCode = http.GET(); + + if (httpCode > 0) { + M5.Lcd.fillScreen(0x1082); + deserializeJson(data, http.getStream()); + + // Top nav + M5.Lcd.setTextColor(0xDEFB); + M5.Lcd.fillRect(0, 0, 320, 22, 0x2104); + M5.Lcd.setCursor(4,4); + M5.Lcd.println(data["hostname"].as()); + + for (size_t i = 0; i < data["temp"]["cores"].size(); i++) + { + if (i == 1) + { + M5.Lcd.setCursor(166,32); + M5.Lcd.fillRoundRect(162, 28, 154, 56, 1, 0x2104); + M5.Lcd.drawXBitmap(305, 32, temp, 7, 14, TFT_WHITE); + } else { + M5.Lcd.setCursor(8,32); + M5.Lcd.fillRoundRect(4, 28, 154, 56, 1, 0x2104); + M5.Lcd.drawXBitmap(147, 32, temp, 7, 14, TFT_WHITE); + } + + M5.Lcd.setTextColor(0xDEFB); + M5.Lcd.print("Core "); + M5.Lcd.print(i); + M5.Lcd.print(": "); + + if (i == 1) + { + M5.Lcd.setCursor(192,52); + } else { + M5.Lcd.setCursor(34,52); + } + M5.Lcd.setTextSize(4); + + if (data["temp"]["cores"][i].as() >= 75) + { + // Very hot + M5.Lcd.setTextColor(0xF0A6); + } else if (data["temp"]["cores"][i].as() >= 55) { + // Meh + M5.Lcd.setTextColor(0xFDC9); + } else { + // Cool + M5.Lcd.setTextColor(0x1572); + } + + M5.Lcd.print(data["temp"]["cores"][i].as()); + M5.Lcd.print(char(247)); + M5.Lcd.println("C"); + M5.Lcd.setTextSize(2); + } + + M5.Lcd.setTextColor(0xDEFB); + + // Memory Usage + M5.Lcd.fillRoundRect(4, 88, 312, 22, 1, 0x2104); + M5.Lcd.setCursor(8, 92); + M5.Lcd.drawXBitmap(297, 92, ram, 15, 10, TFT_WHITE); + + M5.Lcd.print("Memory usage: "); + M5.Lcd.print((data["mem"]["active"].as() / data["mem"]["total"].as()) * 100); + M5.Lcd.println("%"); + + // Swap Usage + M5.Lcd.fillRoundRect(4, 114, 312, 22, 1, 0x2104); + M5.Lcd.setCursor(8, 118); + M5.Lcd.drawXBitmap(299, 118, swap, 13, 13, TFT_WHITE); + + M5.Lcd.print("Swap usage: "); + M5.Lcd.print((data["mem"]["swapused"].as() / data["mem"]["swaptotal"].as()) * 100); + M5.Lcd.println("%"); + + // Disk Usage + M5.Lcd.fillRoundRect(4, 140, 312, 54, 1, 0x2104); + M5.Lcd.setCursor(8, 144); + M5.Lcd.drawXBitmap(298, 144, hdd, 14, 12, TFT_WHITE); + + M5.Lcd.println("Disk usage: "); + for (size_t i = 0; i < data["fs"].size(); i++) + { + M5.Lcd.print(" " + data["fs"][i]["fs"].as() + ": " + data["fs"][i]["use"].as()); + M5.Lcd.println("%"); + } + + // Bottom nav + M5.Lcd.fillRect(0, 218, 320, 22, 0x2104); + M5.Lcd.setCursor(126, 222); + M5.Lcd.println("Update"); + } else { + M5.Lcd.print("HTTP Request Error: "); + M5.lcd.println(httpCode); + } + + http.end(); +} + +void loop() { + if (M5.BtnB.wasPressed()) + { + Serial.println("B"); + update(); + } + + M5.update(); +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..d3c0d88 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# M5_ARNweb +## M5 interface for ARNweb API + +If you want to use this for some reason you need to run [ARNweb API](https://gitea.arnweb.nl/arne/arnweb-api) on a server over HTTPS. Then put the url to the ```/system``` subsection on line 98 and your CA certificate in the ```const char* ca``` on line 34. \ No newline at end of file