Skip to content

Commit

Permalink
nodejs example http-channel-sender
Browse files Browse the repository at this point in the history
  • Loading branch information
dexif committed Feb 15, 2024
1 parent cfeb467 commit a40af36
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
25 changes: 25 additions & 0 deletions http-channel-sender/js/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "nodejs-fetch",
"version": "1.0.0",
"description": "Example of a script for sending a message to the flespi http channel",
"main": "send.js",
"scripts": {
"test": "node send.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/flespi-software/examples.git#master"
},
"keywords": [
"http",
"channel",
"flespi",
"message"
],
"author": "Evgenij Spitsyn [email protected]",
"license": "MIT",
"bugs": {
"url": "https://github.com/flespi-software/examples/issues"
},
"homepage": "https://github.com/flespi-software/examples/tree/master#readme"
}
22 changes: 22 additions & 0 deletions http-channel-sender/js/nodejs/send.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
fetch('http://ch0000000.flespi.gw:00000', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify([
{
ident: 'nodejs-fetch-example',
timestamp: Date.now() / 1000,
'message.type': 'example',
'driver.message': 'Hello, flespi!'
}
])
})
.then(response => {
// Handle response
console.log(response);
})
.catch(error => {
// Handle error
console.log(error);
});

0 comments on commit a40af36

Please sign in to comment.