Skip to content
Snippets Groups Projects
Commit 4a2d5e48 authored by Carlo Guarnieri Calo' Carducci's avatar Carlo Guarnieri Calo' Carducci
Browse files

repo: add datacenter web interface support

parent 47bbf7eb
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,18 @@ flowchart TD
- Description: Set light intensity to **val** [0.0 to 1.0]
## HTTP callbacks
### GET
- **/status**
- Telemetry
- *Format*: `power|<W>;source|<val>`
- *Description*: Log telemetry data, **W** is the input power measured at the meter. Source **val** can be either *grid* or *ups*<br/>(*eg.* `power|0.32;source|grid`)
### POST
- **/post**
- Light
- Format: `light|<val>`
- Description: Set light intensity to **val** [0.0 to 1.0]
### WEB PAGE
[<img src="docs/web_page.png" width="122" height="200">](docs/web_page.png)
## Related Links
......
components/data_center/docs/web_page.png

110 KiB

This diff is collapsed.
components/data_center/html/favicon.ico

4.19 KiB

components/data_center/html/images/battery.png

16.3 KiB

components/data_center/html/images/entity.png

48.7 KiB

components/data_center/html/images/legos.png

6.3 KiB

components/data_center/html/images/tower.png

24.5 KiB

<!DOCTYPE html>
<html>
<title>LEGOS</title>
<meta name="viewport" content="width=device-width, initial-scale=1" charset="UTF-8">
<link rel="stylesheet" href="css/w3.css">
<style>
body,
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: Verdana, sans-serif;
}
</style>
<script>
setInterval(get_status, 1000);
var brightness = 0;
var grid = 1;
function loop_brightness() {
brightness = (brightness + 0.2) % 1.2;
document.getElementById("bulb").style.fillOpacity = String(brightness);
var x = new XMLHttpRequest();
x.open("POST", "post", true);
x.send("light|" + brightness);
}
function set_source(grid) {
document.getElementById("source_grid").style.visibility = (grid == "grid") ? "visible" : "hidden";
document.getElementById("source_ups").style.visibility = (grid == "ups") ? "visible" : "hidden";
}
function get_status() {
var x = new XMLHttpRequest();
x.onreadystatechange = function () {
if (x.readyState == 4 && x.status == 200) {
var resp = x.responseText.split(";");
var powr = resp[0].split("|")[1];
var srce = resp[1].split("|")[1];
document.getElementById("meter_in").innerHTML = powr + " W";
set_source(srce);
}
};
x.open("GET", "status", true);
x.send();
}
</script>
<body>
<!-- HEADER -->
<header class="w3-container w3-border-bottom w3-border-orange">
<div class="w3-row">
<div class="w3-left">
<h3 class="w3-opacity""><b>Data Center</b></h3>
</div>
<div class=" w3-right">
<button class="w3-button w3-text-orange w3-hover-opacity"
onclick="location.href='https://192.168.1.1';">
<h4></h4>
</button>
<button class="w3-button w3-text-orange w3-hover-opacity"
onclick="document.getElementById('help').style.display='block'">
<h4>?</h4>
</button>
</div>
</div>
</header>
<!-- HELP -->
<div id="help" class="w3-panel w3-orange w3-display-container" style="display:none">
<span onclick="this.parentElement.style.display='none'"
class="w3-button w3-orange w3-large w3-display-topright">X</span>
<p class="w3-small">The Data Center represents one of the critical infrastructure for IT operations, which must
provide uninterrupted operation even during a power outage. During the normal operation the power from the
grid is stored in the UPS battery storage, to be later used in case of power grid fault.</p>
</div>
<!-- MAIN -->
<div class="w3-display-container w3-animate-opacity w3-center">
<!-- TOP -->
<div class="w3-row w3-margin-bottom w3-padding">
<div class="w3-left">
<svg viewBox="0 0 44.212619 90" height="80" width="44.21262">
<g transform="translate(-102.13915,-106.12564) scale(1)" stroke-width="1.88976378" stroke="black">
<path d="m 104.88033,139.37353 4.77497,-2.74118" />
<path d="m 143.69901,116.91352 -4.86339,2.82961" />
<path d="m 135.38704,108.86682 -2.74118,4.67121" />
<path d="m 138.83562,136.63235 4.77497,2.74118" />
<path d="m 113.10388,108.86682 2.74118,4.72378" />
<path d="m 104.79191,116.91352 4.86339,2.82961" />
<path d="m 141.48838,128.14352 h 4.86339" />
<path d="m 102.13915,128.14352 h 4.86339" />
<path d="m 124.24534,106.12564 v 4.88902" />
<path
d="m 128.66672,146.6244 c 0,1.51862 0.17685,1.30667 0.17685,4.06756 0,3.07193 -2.37561,4.60834 -4.59811,4.59811 -2.2225,0.0103 -4.59811,-1.52618 -4.59811,-4.59811 0,-2.76089 0.17685,-2.54894 0.17685,-4.06756"
style="fill:none" />
<path
d="m 119.8242,146.44743 c -0.12114,-0.91128 -0.29248,-1.81947 -0.47001,-2.71669 -0.79976,-4.64448 -4.08315,-8.28143 -5.59057,-12.66267 -1.18608,-2.98298 -1.02564,-6.51248 0.6081,-9.2978 1.93545,-3.48423 5.87434,-5.65016 9.87348,-5.65269 3.99914,0.003 7.93803,2.1687 9.87348,5.65293 1.63374,2.78532 1.79418,6.31482 0.6081,9.29779 -1.50742,4.38125 -4.79081,8.0182 -5.59057,12.66268 -0.17753,0.89722 -0.34836,1.80541 -0.46949,2.71657 z"
style="fill:rgb(255, 225, 0)" id="bulb" onclick="loop_brightness()" />
</g>
</svg>
</div>
<div class="w3-right">
<!-- NO CONTROLS -->
</div>
</div>
<!-- MIDDLE -->
<div class="w3-middle">
<img src="images/entity.png" alt="Entity"
style="width:75%;min-height:250px;max-height:500px;max-width:490px">
</div>
<!-- BOTTOM -->
<div class="w3-cell-row w3-margin-top">
<div class="w3-cell w3-cell-bottom" style="width:30%">
<img src="images/tower.png" alt="Power grid"
style="width:70%;min-height:50px;max-height:180px;max-width:138px">
</div>
<div class="w3-cell w3-cell-top" style="width:40%">
<svg viewBox="0 0 120 80" height="80" width="120">
<g transform="translate(60,40)" id="layer1" inkscape:groupmode="layer" inkscape:label="Layer 1">
<rect ry="3.4395833" x="-55" y="-35" height="70" width="110"
style="opacity:1;fill:#e2e2e2;fill-opacity:1;stroke:black;stroke-width:4.5" />
<text x="-45" y="-15" fill="black">Power: </text>
<text x="-20" y="10" fill="black" font-weight="bold" id="meter_in">0 W</text>
</g>
</svg>
<svg class="w3-animate-fading" viewBox="0 0 100 50" height="50" width=100% preserveAspectRatio="none">
<style>
line {
stroke: black;
stroke-width: 2.5;
vector-effect: non-scaling-stroke;
}
</style>
<defs>
<marker id="arrowhead" markerWidth="7" markerHeight="9" markerUnits="userSpaceOnUse" refX="7"
refY="4.5" orient="auto">
<polygon points="0 0, 7 4.5, 0 9" />
</marker>
</defs>
<line x1="50" y1="35" x2="50" y2="0" marker-end="url(#arrowhead)" />
<line x1="0" y1="35" x2="100" y2="35" marker-end="url(#arrowhead)" visibility="visible"
id="source_grid" />
<line x1="50" y1="35" x2="100" y2="35" visibility="hidden" id="source_ups" />
</svg>
</div>
<div class="w3-cell w3-cell-bottom" style="width:30%">
<img src="images/battery.png" alt="UPS"
style="width:70%;min-height:50px;max-height:180px;max-width:138px">
</div>
</div>
</div>
<!-- FOOTER -->
<footer class="w3-container w3-border-top w3-border-orange w3-padding">
<div class="w3-row">
<div class="w3-left">
<p class="w3-opacity w3-small">© ACS 2021</p>
</div>
<div class="w3-right">
<img src="images/legos.png" alt="Logo" style="height:25px">
</div>
</div>
</footer>
</body>
</html>
\ No newline at end of file
......@@ -110,7 +110,7 @@ extern "C" {
#endif
esp_err_t datacenter_init_entity();
esp_err_t datacenter_http_post(char *str);
esp_err_t datacenter_http_resp(char *str);
esp_err_t datacenter_http_read(char *str);
esp_err_t datacenter_mqtt_init(void *client);
esp_err_t datacenter_mqtt_post(void *client);
......@@ -122,7 +122,7 @@ esp_err_t datacenter_mqtt_read(void *event);
// Callback static linking
#define init_entity() datacenter_init_entity()
#define http_post(x) datacenter_http_post(x)
#define http_resp(x) datacenter_http_resp(x)
#define http_read(x) datacenter_http_read(x)
#define mqtt_init(x) datacenter_mqtt_init(x)
#define mqtt_post(x) datacenter_mqtt_post(x)
......
......@@ -501,32 +501,50 @@ esp_err_t datacenter_init_entity()
//
/**
* @brief HTTP post
* Callback for sending web content via HTTP
* @brief HTTP resp
* Callback for responding to HTTP GET requests
*
* @param[in,out] str Message buffer
*
* @return
* - ESP_OK Success
*/
esp_err_t datacenter_http_post(char* str)
esp_err_t datacenter_http_resp(char* str)
{
sprintf(str, "power|%.2f;source|%s",
entity.power_in.power*1000,
entity.power_source?"ups":"grid");
return ESP_OK;
}
/**
* @brief HTTP read
* Callback for reading web content via HTTP
* Callback for reading to HTTP POST requests
*
* @param[in,out] str Message buffer
*
* @return
* - ESP_OK Success
* - ESP_OK : Request correctly processed
* - ESP_FAIL : Request fail
*/
esp_err_t datacenter_http_read(char *str)
{
return ESP_OK;
// Unmarshal value-data pair
msg_payload_t msg_payload;
if (msg_unmarshall(str, "light", &msg_payload)){
float val = atof(msg_payload.val);
if ((val>=0.0) && (val<=1.0)){
entity.led_intensity = val;
ESP_LOGD(TAG, "LIGHT");
}
return ESP_OK;
}
return ESP_FAIL;
}
......@@ -541,10 +559,10 @@ esp_err_t datacenter_mqtt_init(void *client)
{
mqtt_client = (esp_mqtt_client_handle_t)client;
esp_mqtt_client_subscribe(mqtt_client, mqtt_topic_service, MQTT_QOS_LEVEL_0);
esp_mqtt_client_subscribe(mqtt_client, mqtt_topic_service, CONFIG_MQTT_QOS_LEVEL);
ESP_LOGD(TAG, "Subscribing MQTT topic: %s", mqtt_topic_service);
esp_mqtt_client_subscribe(mqtt_client, mqtt_topic_sub, MQTT_QOS_LEVEL_0);
esp_mqtt_client_subscribe(mqtt_client, mqtt_topic_sub, CONFIG_MQTT_QOS_LEVEL);
ESP_LOGD(TAG, "Subscribing MQTT topic: %s", mqtt_topic_sub);
return ESP_OK;
......@@ -564,8 +582,8 @@ esp_err_t datacenter_mqtt_post(void *client)
{
mqtt_client = (esp_mqtt_client_handle_t)client;
char data[64];
sprintf(data,"%10s: %7.1f mA [%4.2f V]\tSource: %4s",TAG,entity.power_in.current,entity.power_in.voltage,entity.power_source?"UPS ":"GRID");
esp_mqtt_client_publish(mqtt_client, mqtt_topic_pub, data, 0, 0, 0);
sprintf(data,"%s: %7.1f mA [%4.2f V]\tSource: %4s",TAG,entity.power_in.current,entity.power_in.voltage,entity.power_source?"UPS ":"GRID");
esp_mqtt_client_publish(mqtt_client, mqtt_topic_pub, data, 0, CONFIG_MQTT_QOS_LEVEL, 0);
ESP_LOGD(TAG, "Outgoing MQTT message: %s\n%s", mqtt_topic_pub, data);
return ESP_OK;
}
......@@ -595,18 +613,18 @@ esp_err_t datacenter_mqtt_read(void *event)
ESP_LOGD(TAG, "Incoming MQTT message: %s\n%s", topic, data);
// Unmarshal value-data pair
mqtt_payload_t mqtt_payload;
msg_payload_t msg_payload;
if (!strcmp(topic,mqtt_topic_service)){
if (mqtt_unmarshall(data, "update", &mqtt_payload))
if (!strcmp(mqtt_payload.val,TAG)){
if (msg_unmarshall(data, "update", &msg_payload))
if (!strcmp(msg_payload.val,TAG)){
ESP_LOGD(TAG, "UPDATE");
// TODO
return ESP_OK;
}
if (mqtt_unmarshall(data, "light", &mqtt_payload)){
float val = atof(mqtt_payload.val);
if (msg_unmarshall(data, "light", &msg_payload)){
float val = atof(msg_payload.val);
if ((val>=0.0) && (val<=1.0)){
entity.led_intensity = val;
ESP_LOGD(TAG, "LIGHT");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment