simple web data widget #15

Merged
ericthelin merged 9 commits from webDataWidget into dev 2024-08-30 00:07:08 +00:00
ericthelin commented 2024-05-18 16:05:14 +00:00 (Migrated from github.com)

Proof of concept for a simple widget to pull data from a web page

https://photos.app.goo.gl/7Fti8xcEfJkqYqjm9

sample server data that outputs data from my computer is below

<?php
$sensorsStr = shell_exec('/usr/bin/sensors -j');
$sensors = json_decode($sensorsStr, true);

$uptimeOutput = shell_exec('uptime');
if (preg_match('/^\s*(..:..:..) up (.*),  ([0-9]+ users),  load average: ([0-9.]+), ([0-9.]+), ([0-9.]+)$/', $uptimeOutput, $output)) {
	$time = $output[1];
	$uptime = preg_replace('/, /', " ", $output[2]);
	$load1min = $output[4];
	$load5min = $output[5];
	$load15min = $output[6];
}

$output = array(
	array(
		'label' => 'CPU',
		'data' => $sensors['coretemp-isa-0000']['Package id 0']['temp1_input'],
	),
	array(
		'label' => 'PNY NVME',
		'data' => $sensors['nvme-pci-0200']['Composite']['temp1_input'],
	),
	array(
		'label' => 'WD Blue NVME',
		'data' => $sensors['nvme-pci-0300']['Composite']['temp1_input'],
	),
	array(
		'label' => 'Uptime',
		'data' => $uptime,
		'labelColor' => 'blue',
		'color' => 'red',
		'background' => 'silver',
	),
	array(
		'label' => 'Load 1 min',
		'data' => $load1min,
		'color' => 'green',
		'labelColor' => 'dArK Green',
	),
);

header('Content-Type: application/json; charset=utf-8');
print json_encode($output) . "\n";

This is the json from the php script

[
  {
    "label": "CPU",
    "data": 48
  },
  {
    "label": "PNY NVME",
    "data": 44.85
  },
  {
    "label": "WD Blue NVME",
    "data": 33.85
  },
  {
    "label": "Uptime",
    "data": "16 days 17:07",
    "labelColor": "blue",
    "color": "red",
    "background": "silver"
  },
  {
    "label": "Load 1 min",
    "data": "1.87",
    "color": "green",
    "labelColor": "dArK Green"
  }
]
Proof of concept for a simple widget to pull data from a web page https://photos.app.goo.gl/7Fti8xcEfJkqYqjm9 sample server data that outputs data from my computer is below ``` <?php $sensorsStr = shell_exec('/usr/bin/sensors -j'); $sensors = json_decode($sensorsStr, true); $uptimeOutput = shell_exec('uptime'); if (preg_match('/^\s*(..:..:..) up (.*), ([0-9]+ users), load average: ([0-9.]+), ([0-9.]+), ([0-9.]+)$/', $uptimeOutput, $output)) { $time = $output[1]; $uptime = preg_replace('/, /', " ", $output[2]); $load1min = $output[4]; $load5min = $output[5]; $load15min = $output[6]; } $output = array( array( 'label' => 'CPU', 'data' => $sensors['coretemp-isa-0000']['Package id 0']['temp1_input'], ), array( 'label' => 'PNY NVME', 'data' => $sensors['nvme-pci-0200']['Composite']['temp1_input'], ), array( 'label' => 'WD Blue NVME', 'data' => $sensors['nvme-pci-0300']['Composite']['temp1_input'], ), array( 'label' => 'Uptime', 'data' => $uptime, 'labelColor' => 'blue', 'color' => 'red', 'background' => 'silver', ), array( 'label' => 'Load 1 min', 'data' => $load1min, 'color' => 'green', 'labelColor' => 'dArK Green', ), ); header('Content-Type: application/json; charset=utf-8'); print json_encode($output) . "\n"; ``` This is the json from the php script ``` [ { "label": "CPU", "data": 48 }, { "label": "PNY NVME", "data": 44.85 }, { "label": "WD Blue NVME", "data": 33.85 }, { "label": "Uptime", "data": "16 days 17:07", "labelColor": "blue", "color": "red", "background": "silver" }, { "label": "Load 1 min", "data": "1.87", "color": "green", "labelColor": "dArK Green" } ] ```
ericthelin (Migrated from github.com) reviewed 2024-05-18 16:18:24 +00:00
@ -0,0 +1,28 @@
#ifndef WEB_DATA_WIDGET_H
ericthelin (Migrated from github.com) commented 2024-05-18 16:18:23 +00:00

I am thinking I should create a "data class" to store the above items as they all go together. and it would be a lot cleaner.

I am thinking I should create a "data class" to store the above items as they all go together. and it would be a lot cleaner.
ericthelin (Migrated from github.com) reviewed 2024-05-18 16:18:53 +00:00
@ -0,0 +1,28 @@
#ifndef WEB_DATA_WIDGET_H
ericthelin (Migrated from github.com) commented 2024-05-18 16:18:53 +00:00

obviously this needs to be moved to a config

obviously this needs to be moved to a config
ericthelin (Migrated from github.com) reviewed 2024-05-18 16:20:09 +00:00
@ -81,6 +82,9 @@ void setup() {
widgetSet->add(new ClockWidget(*sm));
ericthelin (Migrated from github.com) commented 2024-05-18 16:20:09 +00:00

We are going to need to build a config option to order the widgets or disable unwanted ones soon.

We are going to need to build a config option to order the widgets or disable unwanted ones soon.
ericthelin (Migrated from github.com) reviewed 2024-05-18 16:20:41 +00:00
@ -0,0 +1,91 @@
ericthelin (Migrated from github.com) commented 2024-05-18 16:20:41 +00:00

screen locations should probably be configurable

screen locations should probably be configurable
ericthelin (Migrated from github.com) reviewed 2024-05-18 16:21:52 +00:00
@ -0,0 +1,91 @@
ericthelin (Migrated from github.com) commented 2024-05-18 16:21:52 +00:00

This should probably be in a global library as it seems like it will be useful for multiple widgets.

This should probably be in a global library as it seems like it will be useful for multiple widgets.
ericthelin (Migrated from github.com) reviewed 2024-05-18 16:22:46 +00:00
@ -0,0 +1,91 @@
ericthelin (Migrated from github.com) commented 2024-05-18 16:22:46 +00:00

I think I am liking "fingerprint" more than "stamp" as I did in weatherWidget. Thoughts?

I think I am liking "fingerprint" more than "stamp" as I did in weatherWidget. Thoughts?
ericthelin (Migrated from github.com) reviewed 2024-05-18 16:23:43 +00:00
@ -0,0 +80,4 @@
m_lastUpdate = millis();
} else {
// Handle JSON deserialization error
Serial.println("deserializeJson() failed");
ericthelin (Migrated from github.com) commented 2024-05-18 16:23:43 +00:00

we should probably build an error screen that can be displayed for cases like this

we should probably build an error screen that can be displayed for cases like this
ericthelin (Migrated from github.com) reviewed 2024-05-18 16:24:01 +00:00
@ -0,0 +84,4 @@
}
} else {
// Handle HTTP request error
Serial.printf("HTTP request failed, error: %s\n", http.errorToString(httpCode).c_str());
ericthelin (Migrated from github.com) commented 2024-05-18 16:24:01 +00:00

Same error screen comment as above

Same error screen comment as above
ericthelin (Migrated from github.com) reviewed 2024-05-18 16:28:29 +00:00
@ -0,0 +1,91 @@
ericthelin (Migrated from github.com) commented 2024-05-18 16:28:29 +00:00

these are no longer used

these are no longer used
ericthelin (Migrated from github.com) reviewed 2024-05-18 16:30:09 +00:00
@ -0,0 +1,91 @@
ericthelin (Migrated from github.com) commented 2024-05-18 16:30:09 +00:00

we should also check the string for newlines and break them up. But with variable font sizes x,y positioning becomes tricky

we should also check the string for newlines and break them up. But with variable font sizes x,y positioning becomes tricky
Sign in to join this conversation.
No description provided.