OpenEVSE EV Charging station with Emoncms WiFi Integration

Hi Glyn, i really appreciate your feedback, having a look at someone else’s code is always hard so thanks for the opportunity.

Let’s do this step-by-step.

1. My EVSE connects and it’s host name that is used for mDNS service is the MQTT topic:

post:   evse/cab123EVSE/from
listen: evse/cab123EVSE/to 

2. NodeRED listens to this topics:

evse/+/from/#

“evse” is the base MQTT configured on my EVSE and is used to separate traffic for easier debugging.
“+” is any name of the EVSE.
“from” is hard coded. It represents messages coming from the EVSE

So with this info i’m able to reply to any EVSE that talks with me. Because the reply topic is simply swapping “from” to “to”

evse/+/to

Now to port this idea to OpenEVSE:

  1. OpenEVSE posts data to emoncms
  2. emoncms posts data to MQTT, topic evse/glynEVSE/from
  3. NodeRED need to send a message to the EVSE.

How?

Q1. In order to do do this without MQTT’ing OpenEVSE we need to know it’s IP address or mDNS host when we want to reply
Q2. Also we need to diferentiate OpenEVSE (RAPI) from the other EVSE’s so NodeRED takes additional step and builds the correpondent RAPI call

We could use the normal reply channel evse/glynEVSE/to and develop a new function that parses the message and sends a RAPI call. However, the original message need reachability information (Q1) and a flag indicating it is a OpenEVSE EVSE (Q2).

Something along these lines:

[{“id”:“987b588a.29ddd”,“type”:“mqtt in”,“z”:“2ad08bfd.22919c”,“name”:“Control OpenEVSE”,“topic”:“evse/+/to/#”,“qos”:“2”,“broker”:“858bdb7c.9c0948”,“x”:152.5,“y”:1201,“wires”:[[“7913113c.e62b6”]]},{“id”:“7913113c.e62b6”,“type”:“function”,“z”:“2ad08bfd.22919c”,“name”:“”,“func”:“// D[0] = "OpenEVSE"\n// D[1] = 192.168.1.1\n// D[2] = A\n// D[3] = 16\n\nvar D = msg.payload.split(","); // split incoming message\n\nif(D[0] != "OpenEVSE") return[null];\n\nvar rapi;\n\nif(D[2] == "A") {\n rapi = "$SC";\n if(parseInt(D[3]) == 6) { rapi += D[3] + "*10"; }\n if(parseInt(D[3]) == 7) { rapi += D[3] + "*11"; }\n if(parseInt(D[3]) == 8) { rapi += D[3] + "*12"; }\n if(parseInt(D[3]) == 9) { rapi += D[3] + "*13"; }\n if(parseInt(D[3]) == 10) { rapi += D[3] + "*3B"; }\n if(parseInt(D[3]) == 11) { rapi += D[3] + "*3C"; }\n if(parseInt(D[3]) == 12) { rapi += D[3] + "*3D"; }\n if(parseInt(D[3]) == 13) { rapi += D[3] + "*3E"; }\n if(parseInt(D[3]) == 14) { rapi += D[3] + "*3F"; }\n if(parseInt(D[3]) == 15) { rapi += D[3] + "*40"; }\n if(parseInt(D[3]) == 16) { rapi += D[3] + "*41"; }\n if(parseInt(D[3]) == 17) { rapi += D[3] + "*42"; }\n if(parseInt(D[3]) == 18) { rapi += D[3] + "*43"; }\n if(parseInt(D[3]) == 19) { rapi += D[3] + "*44"; }\n if(parseInt(D[3]) == 20) { rapi += D[3] + "*3C"; }\n if(parseInt(D[3]) == 21) { rapi += D[3] + "*3D"; }\n if(parseInt(D[3]) == 22) { rapi += D[3] + "*3E"; }\n if(parseInt(D[3]) == 23) { rapi += D[3] + "*3F"; }\n if(parseInt(D[3]) == 24) { rapi += D[3] + "*40"; }\n if(parseInt(D[3]) == 25) { rapi += D[3] + "*41"; }\n if(parseInt(D[3]) == 26) { rapi += D[3] + "*42"; }\n if(parseInt(D[3]) == 27) { rapi += D[3] + "*43"; }\n if(parseInt(D[3]) == 28) { rapi += D[3] + "*44"; }\n if(parseInt(D[3]) == 29) { rapi += D[3] + "*45"; }\n if(parseInt(D[3]) == 30) { rapi += D[3] + "*3D"; }\n if(parseInt(D[3]) == 31) { rapi += D[3] + "*3E"; }\n if(parseInt(D[3]) == 32) { rapi += D[3] + "*3F"; }\n}\n\nmsg.url = "http://" + D[1];\nmsg.payload = "r?rapi=" + rapi;\nmsg.method = "GET";\nmsg.headers = "text/html";\n\nreturn msg;”,“outputs”:“1”,“noerr”:0,“x”:368.5,“y”:1241,“wires”:[[“e02ecb6b.2bbd58”]]},{“id”:“e02ecb6b.2bbd58”,“type”:“debug”,“z”:“2ad08bfd.22919c”,“name”:“”,“active”:true,“console”:“false”,“complete”:“true”,“x”:553.5,“y”:1200,“wires”:},{“id”:“858bdb7c.9c0948”,“type”:“mqtt-broker”,“z”:“2ad08bfd.22919c”,“broker”:“192.168.20.240”,“port”:“1883”,“clientid”:“”,“usetls”:false,“verifyservercert”:true,“compatmode”:true,“keepalive”:“60”,“cleansession”:true,“willTopic”:“”,“willQos”:“0”,“willRetain”:null,“willPayload”:“”,“birthTopic”:“”,“birthQos”:“0”,“birthRetain”:null,“birthPayload”:“”}]

You can test by posting to MQTT:

mosquitto_pub -t evse/glynEVSE/to -m “OpenEVSE,192.168.20.1,A,18”

This would be really flexible since it easily accomodates more RAPI messages.

Let me know what you think