I would like to control the 40A Deluxe Level1&2 using a rpi and Node.js, instead of the firmware provided with the wi-fi board.
To do so, instead of the wifi board, I connected a rpi3 (using GPIO, not USB) which I would like to use to send RAPI commands using the node.js library Node-Serialport.
I managed to successfully control the OpenEVSE from the rpi using the command line tools provided by the library (serialport-term)
However I can’t achieve the same using a simple script like this:
var SerialPort = require('serialport');
var port = new SerialPort('/dev/ttyS0', {
baudRate: 115200
}, function(err) {
if (err) {
return console.log('Error: ', err.message);
}
console.log("Port is open: ", port.isOpen)
});
port.on("open", function () {
console.log("open");
port.on("data", function(data) {
console.log("data received: " + data);
});
port.write("$SC 8", function(err, res) {
if (err) {
return console.log('Error on write: ', err.message);
}
console.log('message written');
});
});
The output is the following:
but the charger doesn’t react. Do you know what I’m doing wrong? Any help would be very much appreciated.
Debug:
serialport:binding:auto-detect loading LinuxBinding +0ms
serialport:main opening path: /dev/ttyS0 +0ms
serialport:bindings open +0ms
serialport:poller Creating poller +0ms
serialport:main opened path: /dev/ttyS0 +9ms
open
serialport:main _write 6 bytes of data +6ms
serialport:bindings write 6 bytes +14ms
Port is open: true
serialport:unixWrite Starting write 6 bytes offset 0 bytesToWrite 6 +0ms
serialport:main _read reading +7ms
serialport:bindings read +7ms
serialport:unixRead Starting read +0ms
serialport:unixWrite write returned null 6 +8ms
serialport:unixWrite wrote 6 bytes +1ms
serialport:unixWrite Finished writing 6 bytes +0ms
serialport:main binding.write write finished +6ms
message written
serialport:unixRead waiting for readable because of code: EAGAIN +5ms
serialport:poller Polling for "readable" +22ms
Have you tried testing RAPI communication via direct simple serial (115200 baud) e.g.
sending $GV via serial to the OpenEVSE should return the version number of the firmware:
>$OK 4.8.0 3.0.1^2E
2E is the HEX checksum.
Once your confident you have RAPI un and running you can then get you application invovlved. I’m sorry I have no experience with node-serial / nodejs.
What is your end goal? The OpenEVSE WiFi Gateway we have developed for use with the OpenEVSE allows rapi commands to be issued via HTTP/MQTT and via the web-interface as well as providing a functional GUI:
which, I guess, is odd since bought the openevse a month ago. All the other commands seem to work fine.
Anyway, the reason why I would like to integrate nodejs is the following:
I am a phd student (energy engineer) and my research consists in creating a local power exchange for electricity trading at neighborhood level (like a micro-market) based on blockchain and smart contracts. This is actually the continuation of my master thesis that started more than a year ago with this post Installation of an Ethereum client on emonPi/emonBase?. In the meanwhile I achieved what I was asking in the post and I developed the project enough to start a phd.
Now I would like to add a “blockchain-connected” EV charger (the OpenEVSE) to the project in order to use it as flexible load. Since my current set-up works on rpi with web3.js (a javascript library for the integration of ethereum blockchain with javascript and therefore nodejs) i thought to try this library (node-serialport) for a more seamless integration of what I have with the RAPI commands of the charger.
In addition I would like to embed the rpi board (e.g. rpi zero w) inside the charger (like the wifi board now) rather than having it outside and communicating through mqtt or http.
Sorry for the long text, but it was necessary to explain you my goal.
I’ll update the firmware of the OpenEVSE board and check if this solves the problem. In the meantime, I found this conversation in the OpenEVSE google group where they discuss a similar topic. They say that the OpenEVSE board only has standard 5 volt FTDI connectors and a level shifter is needed since the gpio of the rpi3 are not 5v tolerant. The post id more than 2 years old, does this still apply today?
We have only recently started shipping units with V4.8.0. You can update the FW using an ISP programmer to upload the .hex:
It you want to run the latest version (currently in dev, but seems stable) you could use vD4.10.2.EU. This version has been customised by OpenEnergyMonitor to have some settings specific to EU/UK power systems. See release notes.
It’s great to hear about your blockchain project using OpenEVSE. Sounds really interesting. Please keep us updated.
I updated the firmware to the 4.8 and i get the correct response when I type $GV in the terminal, however I’m still struggling with the node-serialport library.
These are the options that i’m using to setup the port:
where data is a string (e.g. “$SC 10”) and encoding is “utf8”. I could also use buffer and array for data and ‘ascii’, ‘base64’, ‘binary’, and ‘hex’ for encoding.
Can you spot any error?
Anyway I will definitely keep you updated with my progress
Sorry I can’t, the issue is obviously something to do with the node-seriaport. I have no experience of using nodejs.
Could you attach a serial receiver to take a look at the serial ouput of node-serialport and compare to the direct serial. See if you can spot the difference! I’ve used nodered serial port in the past to communicate with OpenEVSE with no problem: