Skip to content

Commit

Permalink
Merge pull request #16 from EdgePi-Cloud/impl_rpc!
Browse files Browse the repository at this point in the history
Implement rpc
  • Loading branch information
iaj2 authored Aug 3, 2023
2 parents dc4adb1 + 13682f7 commit 80a15ca
Show file tree
Hide file tree
Showing 7 changed files with 4,334 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Publish Package to npm
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 OSENSA Innovations Corp.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
# node-red-edgepi-thermocouple
# node-red-edgepi-thermocouple

# Using Node Red
If Node-RED is not yet installed, please see instructions for installing Node-RED at https://github.com/osensa/node-red-edgepi-led-array.

# Installing this node
1. git clone this repository
2. Change to project directory: $ cd node-red-edgepi-thermocouple
3. Install dependencies: $ npm install
4. Change to .node-red directory: $ cd ~/.node-red
5. $ npm install path_to_project_directory

# Troubleshooting
* Note: upon being deployed, this node will run a bash executable to install Python module dependencies. The executable may not have the necessary file permissions to perform these operations. If an error related to file permissions is encountered, enter the following in the project directory, in order to give the bash script execute permission:
- `$ chmod +x edgepi-thermocouple`

# About
This node sets up a multiprocessing environment consisting of the following features:
1. Node runs in parent process (where Node-RED is running), and receives as input an injected value. This injected value can be any value, its purpose is only to signal the Node to trigger a "sample temperature" command to the Python script running in the child process.
2. A child process running a Python script which uses code provided by Steven to sample ambient temperature using the RTU-Thermocouple.
3. The parent process communicates with the child process, allowing the node in the parent process to receive temperature readings and display them in Node-RED.

# Sample Flow and UI Dashboard using thermocouple node and led-trigger node
This sample flow shows the thermocouple node being used to obtain temperature readings, which are then used along with the LED trigger node (https://github.com/osensa/node-red-edgepi-led-array) to toggle an EdgePi LED on/off. Here, the on/off temperature is 24.5 degrees Celsius.
![image](https://user-images.githubusercontent.com/77416463/168688664-a7c5646e-a811-49d5-a6bd-0015b8b9d99d.png)

![image](https://user-images.githubusercontent.com/77416463/168688751-14f4eef6-b45b-4bfd-a072-582adcf61c7d.png)
34 changes: 34 additions & 0 deletions edgepi-thermocouple.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script type="text/javascript">
RED.nodes.registerType('edgepi-thermocouple-node',{
category: 'Osensa EdgePi',
color: '#a6bbcf',
defaults: {
name: { value:"" },
Method: { value: "singleSample"}
},
inputs:1,
outputs:1,
icon: "font-awesome/fa-thermometer-2",
label: function() {
return this.name||"thermocouple-node";
}
});
</script>

<script type="text/html" data-template-name="edgepi-thermocouple-node">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-Method">Method</label>
<select id="node-input-Method">
<option value="singleSample">singleSample</option>
<option value="readTemperatures">readTemperatures</option>
</select>
</div>
</script>

<script type="text/html" data-help-name="edgepi-thermocouple-node">
<p>A node that handles handles passing commands to RTU Thermocoupler and displaying output</p>
</script>
40 changes: 40 additions & 0 deletions edgepi-thermocouple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = function(RED) {
const rpc = require("@edgepi-cloud/edgepi-rpc")

function ThermocoupleNode(config) {
RED.nodes.createNode(this, config);
const node = this;
node.Method = config.Method;
console.log(node.Method)
const tc = new rpc.TcService()
this.on('input', async function (msg, send, done) {
try{
if(node.Method){
let temps = await tc[node.Method]();
msg.payload = temps;
}
else{
msg.payload = "Select a method for edgepi thermocouple"
}
}
catch(err) {
console.error(err);
msg.payload = err;
}

send(msg);
if (done) {
done();
}
})


// handle exit
node.on("close", function(done) {
node.status({fill:"grey", shape:"ring", text:"tc terminated"});

done();
});
}
RED.nodes.registerType("edgepi-thermocouple-node", ThermocoupleNode);
}
Loading

0 comments on commit 80a15ca

Please sign in to comment.