Skip to content

Commit edcd510

Browse files
committed
Prototype
0 parents  commit edcd510

File tree

10 files changed

+835
-0
lines changed

10 files changed

+835
-0
lines changed

projects/dashboard/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules/

projects/dashboard/index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const ModbusRTU = require('modbus-serial');
2+
const client = new ModbusRTU();
3+
4+
const toUint16 = (string) => new Uint16Array(new TextEncoder('utf-8').encode(string));
5+
6+
const wifiCredentials = {
7+
ssid: 'YOURSSID',
8+
password: 'YOURPASSWORD'
9+
};
10+
11+
client.connectRTUBuffered(
12+
'/dev/tty.usbserial-1410',
13+
{
14+
baudRate: 9600
15+
}
16+
).then( async () => {
17+
client.setID(1);
18+
19+
await client.writeRegisters(30, toUint16(wifiCredentials.ssid))
20+
.then(() => {
21+
return client.readHoldingRegisters(30, 20)
22+
.then(val => {
23+
console.log( 'got', val.buffer.toString() )
24+
});
25+
});
26+
27+
await client.writeRegisters(10, toUint16(wifiCredentials.password))
28+
.then(() => {
29+
return client.readHoldingRegisters(10, 20)
30+
.then(val => {
31+
console.log( 'got', val.buffer.toString() )
32+
});
33+
});
34+
35+
return client.writeCoil(10, true).then( r => console.log(r) );
36+
} ).catch( err => console.error( err ) );

0 commit comments

Comments
 (0)