Skip to content

Commit

Permalink
added PixelIt UUID to Core-Node
Browse files Browse the repository at this point in the history
  • Loading branch information
o0shojo0o committed Oct 7, 2024
1 parent dae71f7 commit 6701000
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

## Changelog

### 0.4.0 (2024-10-07)

- (o0shojo0o) added PixelIt UUID to Core-Node (is necessary in the future to use the API)
- (o0shojo0o) update dependencies

### 0.3.14 (2022-08-16)

- (o0shojo0o) better JSON error handling
Expand Down
9 changes: 8 additions & 1 deletion pixelit/core.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
name: {
value: "Core"
},
uuid: {
value: ""
},
ip: {
value: ""
},
Expand All @@ -26,7 +29,11 @@
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</div>
<div class="form-row">
<label for="node-input-uuid"><i class="icon-tag"></i> PixelIt UUID</label>
<input type="text" id="node-input-uuid" placeholder="PixelIt UUID (Required to use the API)">
</div>
<div class="form-row">
<label for="node-input-ip"><i class="icon-tag"></i> IP-Address</label>
<input type="text" id="node-input-ip" placeholder="IP-Address (Optional)">
Expand Down
11 changes: 7 additions & 4 deletions pixelit/core.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ts-check
"use strict";
const tools = require("./lib/tools");
const axios = require("axios").default;
const axios = require("axios");
const errorImage = '[64512,0,0,0,0,0,0,64512,0,64512,0,0,0,0,64512,0,0,0,64512,0,0,64512,0,0,0,0,0,64512,64512,0,0,0,0,0,0,64512,64512,0,0,0,0,0,64512,0,0,64512,0,0,0,64512,0,0,0,0,64512,0,64512,0,0,0,0,0,0,64512]';

module.exports = (red) => {
Expand All @@ -15,6 +15,7 @@ module.exports = (red) => {
let sleepModeActive = context.get("sleepModeActive") || false;
let sendOverHTTPActive = true;
let mqttMasterTopic = tools.getValue(red, config.masterTopic, msg) || "";
const uuid = config.uuid;

// Clean Master Topic
if (mqttMasterTopic.substr(mqttMasterTopic.length - 1) === "/") {
Expand Down Expand Up @@ -413,6 +414,8 @@ module.exports = (red) => {
let webBmp = errorImage;
let webResult;



if (input) {
if (String(input).includes(",")) {
return input;
Expand All @@ -425,7 +428,7 @@ module.exports = (red) => {
}

try {
const res = await axios.get(`https://pixelit.bastelbunker.de/API/GetBMPByID/${input}`, {
const res = await axios.get(`https://pixelit.bastelbunker.de/API/GetBMPByID/${input}?uuid=${uuid}`, {
headers: {
"User-Agent": "Node_Red_Core",
"Content-type": "application/json; charset=utf-8",
Expand All @@ -434,7 +437,7 @@ module.exports = (red) => {
});
webResult = res.data;
} catch (error) {
node.status({
node.status({
fill: "red",
shape: "dot",
text: `Failed to download icon ${input}. Check Node-RED log.`,
Expand All @@ -443,7 +446,7 @@ module.exports = (red) => {
webResult = undefined;
}

if (webResult && webResult.id && webResult.id != 0) {
if (webResult?.id != 0) {
webBmp = webResult.rgB565Array;
context.set(`bmpCache_${input}`, webBmp);
}
Expand Down

0 comments on commit 6701000

Please sign in to comment.