Commit 6d3d0170 by Tref

update with better structure

parent f11975ed
Java project requires Java11. <br/>
ESP32 is built for WEMOS minikit.
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
#include <Arduino.h> #include <Arduino.h>
#define PORT 1883 #define PORT 1883
#define LED 2
const char* WIFI_SSID = "Telia-9E1E41"; const char* WIFI_SSID = "Telia-9E1E41";
const char* WIFI_PASS = "XPC47UPGRT"; const char* WIFI_PASS = "XPC47UPGRT";
const char* server = "192.168.1.188"; const char* server = "192.168.1.188";
long lastMsg = 0;
WiFiClient client; WiFiClient client;
PubSubClient mqttClient(client); PubSubClient mqttClient(client);
void setup() { void setup() {
...@@ -18,29 +19,49 @@ void setup() { ...@@ -18,29 +19,49 @@ void setup() {
{ {
delay(3000); delay(3000);
} }
pinMode(LED, OUTPUT);
mqttClient.setServer(server, PORT); mqttClient.setServer(server, PORT);
// put your setup code here, to run once: // put your setup code here, to run once:
delay(5000); delay(5000);
while(1){ while(1){
if(mqttClient.connect("ardu")){ if (mqttClient.connect("ardu")) {
break; break;
} else {
delay(1000);
} }
} }
mqttClient.setCallback(subscribeReceive); mqttClient.setCallback(subscribeReceive);
mqttClient.subscribe("/master/app/server/diagnostics/browser/blockreading");
mqttClient.subscribe("/master/app/server/diagnostics/browser/errorreading");
} }
void loop() { void loop() {
// put your main code here, to run repeatedly: if (!mqttClient.connected()) {
while (Serial.available()) { reconnect();
String s = Serial.readString(); }
int n = s.length(); long now = millis();
char c[n + 1]; if (now - lastMsg > 2000) {
strcpy(c, s.c_str()); mqttClient.loop();
switch(c[0]){ lastMsg = now;
case 'p': }
mqttClient.publish("/master/app/server/diagnostics/ecu/errorreading", c); }
Serial.write("done");
break; void reconnect() {
// Loop until we're reconnected
while (!mqttClient.connected()) {
// Attempt to connect
if (mqttClient.connect("ardu")) {
mqttClient.subscribe("/master/app/server/diagnostics/browser/blockreading");
mqttClient.subscribe("/master/app/server/diagnostics/browser/errorreading");
} else {
delay(500);
} }
} }
} }
...@@ -55,9 +76,118 @@ void MQTTdataParser(byte* payload, char str[], unsigned int length){ ...@@ -55,9 +76,118 @@ void MQTTdataParser(byte* payload, char str[], unsigned int length){
void subscribeReceive(char* topic, byte* payload, unsigned int length) void subscribeReceive(char* topic, byte* payload, unsigned int length)
{ {
char str[length+1]; char str[length+1];
MQTTdataParser(payload, str, length); MQTTdataParser(payload, str, length);
if(strcmp(topic, "/master/app/server/diagnostics/user/grpreading")){ long value = strtol(str, NULL, 10);
//Serial.print(value);
//Serial.print(topic);
if(strcmp(topic, "/master/app/server/diagnostics/browser/blockreading") == 0){
grpReading((int)value);
}else if(strcmp(topic, "/master/app/server/diagnostics/browser/errorreading") == 0){
value = strtol("203", NULL, 10);
errorReading((int)value);
}
}
void errorReading(int block){
int i = 0;
Serial.write(block);
while (!Serial.available()) {
i++;
if(i == 9999999)
return;
}
delay(10000);
int buf = Serial.read();
if (buf == 'D'){
char c[256];
i = 0;
while (Serial.available()) {
c[i] = Serial.read();
i++;
}
//c[i-1] = '\0';
mqttClient.publish("/master/app/server/diagnostics/ecu/errorreading", c);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
buf = Serial.read();
}
}
void grpReading(int block){
Serial.write(block);
long i = 0;
while (!Serial.available()) {
i++;
if(i == 9999999)
return;
} }
delay(10000);
int buf = Serial.read();
if (buf == 'G'){
int dat[12] = {0};
char h[5];
int i = 0;
int flag1 = 0;
int k = 0;
//Serial.print("\n");
do{
if(Serial.available()) {
delay(5);
buf = Serial.read();
//Serial.write(buf);
if(buf != ';'){
flag1 = 0;
//dat[i] += (buf)*k;
h[k] = buf;
//Serial.write(dat[i]);
//Serial.print(" ");
k++;
}else if(!flag1 && buf == ';'){
//Serial.print("\n");
dat[i] = atoi(h);
h[0] = '\0';
h[1] = '\0';
h[2] = '\0';
h[3] = '\0';
h[4] = '\0';
i++;
flag1 = 1;
k = 0;
}else if(flag1 && buf == ';'){
//Serial.print("\n");
//Serial.print("\n");
break;
}
}
}while(i<12);
char str[256] = "\0";
char temp[5];
int j = 0;
char ix = i + '0';
//Serial.print(ix);
//Serial.print("\n");
for(;j<i;j++){
sprintf(temp, "%d;", dat[j]);
//itoa(dat[j], temp, 10);
strcat(str, temp);
//strcat(str, ";");
}
mqttClient.publish("/master/app/server/diagnostics/ecu/blockreading", str);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
buf = Serial.read();
//Serial.write(str);
}
} }
\ No newline at end of file
[{"id":"9a49eee8.a93ee","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"6923df5.315752","type":"ui_button","z":"9a49eee8.a93ee","name":"","group":"6f182569.913e1c","order":2,"width":0,"height":0,"passthru":false,"label":"Engine diagnostics","tooltip":"Select the block number & start diagnostics","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":250,"y":140,"wires":[["d2b1345e.189638"]]},{"id":"d2b1345e.189638","type":"ui_text_input","z":"9a49eee8.a93ee","name":"","label":"Block number [1-127]","tooltip":"Select the block number to read","group":"6f182569.913e1c","order":1,"width":0,"height":0,"passthru":false,"mode":"number","delay":"0","topic":"","x":250,"y":200,"wires":[["293414fd.45d3ac"]]},{"id":"922ec540.570c88","type":"mqtt out","z":"9a49eee8.a93ee","name":"","topic":"/master/app/server/diagnostics/browser/blockreading","qos":"","retain":"","broker":"278f5a97.697a66","x":640,"y":120,"wires":[]},{"id":"293414fd.45d3ac","type":"function","z":"9a49eee8.a93ee","name":"","func":"if (msg.payload >= 1 && msg.payload <= 127){\n msg.payload = msg.payload.toString();\n msg.topic = \"ECU request\";\n return [msg, null];\n}else{\n msg.payload = \"ERROR: number must be between 1-127, was: \" + msg.payload;\n msg.topic = \"error\"\n return [null, msg];\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","x":480,"y":200,"wires":[["922ec540.570c88","ceceb9d8.c18858","e6ed4f92.c07ab"],["e36ef48f.2686d8"]]},{"id":"bb58dd9a.a96a","type":"ui_toast","z":"9a49eee8.a93ee","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":false,"topic":"","name":"","x":710,"y":40,"wires":[]},{"id":"b2a99d47.454e9","type":"function","z":"9a49eee8.a93ee","name":"","func":"if(msg.topic == \"error\"){\n return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":40,"wires":[["bb58dd9a.a96a"]]},{"id":"289af6a5.2334da","type":"link in","z":"9a49eee8.a93ee","name":"","links":["e36ef48f.2686d8","9b498cce.cf961","6b54d767.f6fd18","eb397f32.89c47","e0353736.ea04e8","27953a49.d1acc6","1b1a4a91.7d9ee5","a00fa8e2.3f1388"],"x":75,"y":40,"wires":[["b2a99d47.454e9"]]},{"id":"e36ef48f.2686d8","type":"link out","z":"9a49eee8.a93ee","name":"","links":["289af6a5.2334da"],"x":435,"y":240,"wires":[]},{"id":"6aa2a1d1.42076","type":"mqtt in","z":"9a49eee8.a93ee","name":"","topic":"/master/app/server/diagnostics/ecu/blockreading","qos":"2","datatype":"auto","broker":"278f5a97.697a66","x":280,"y":400,"wires":[["44262ada.4091d4","da108f5d.6f0d1"]]},{"id":"81d4c78c.5ecab8","type":"comment","z":"9a49eee8.a93ee","name":"","info":"ECU sends bunch of data to microC.\nEach block has up to 4 sensors.\nEach sensor send 2 integers.\nData is calculated.\nOutput is 1 string for each sensor.\nData should be sent like:\n\"sensor;data;sensor;data;sensor;data;sensor;data\"\nempty read should be (?)\n","x":340,"y":340,"wires":[]},{"id":"44262ada.4091d4","type":"function","z":"9a49eee8.a93ee","name":"","func":"if(msg.payload == \"timeout\"){\n return [null, null, null, null, msg];\n}\nvar tokens = msg.payload.split(\";\");\n\nvar o1 = {topic: \" \", payload: \" \"};\nvar o2 = {topic: \" \", payload: \" \"};\nvar o3 = {topic: \" \", payload: \" \"};\nvar o4 = {topic: \" \", payload: \" \"};\n/*var o = [msg];\nfor(i=0;i<4;i++){\n var tempMsg = msg;\n tempMsg.topic = tokens[i*2];\n tempMsg.payload = tokens[i*2+1];\n o.push(tempMsg);\n //o.push(msg);\n}*/\no1.topic = tokens[0];\no2.topic = tokens[2];\no3.topic = tokens[4];\no4.topic = tokens[6];\no1.payload = tokens[1];\no2.payload = tokens[3];\no3.payload = tokens[5];\no4.payload = tokens[7];\nreturn [o1, o2, o3, o4, null];\n//return msg_array;","outputs":5,"noerr":0,"initialize":"","finalize":"","x":560,"y":400,"wires":[["3f9f0d54.9a1862"],["9e7934fe.9e2a18"],["71a11ba1.1d4494"],["67c47310.d092fc"],["9b498cce.cf961"]]},{"id":"3f9f0d54.9a1862","type":"ui_text","z":"9a49eee8.a93ee","group":"6f182569.913e1c","order":6,"width":0,"height":0,"name":"","label":"{{msg.topic}}","format":"{{msg.payload}}","layout":"row-center","x":830,"y":340,"wires":[]},{"id":"9e7934fe.9e2a18","type":"ui_text","z":"9a49eee8.a93ee","group":"6f182569.913e1c","order":7,"width":0,"height":0,"name":"","label":"{{msg.topic}}","format":"{{msg.payload}}","layout":"row-center","x":850,"y":380,"wires":[]},{"id":"71a11ba1.1d4494","type":"ui_text","z":"9a49eee8.a93ee","group":"6f182569.913e1c","order":8,"width":0,"height":0,"name":"","label":"{{msg.topic}}","format":"{{msg.payload}}","layout":"row-center","x":870,"y":420,"wires":[]},{"id":"67c47310.d092fc","type":"ui_text","z":"9a49eee8.a93ee","group":"6f182569.913e1c","order":9,"width":0,"height":0,"name":"","label":"{{msg.topic}}","format":"{{msg.payload}}","layout":"row-center","x":890,"y":460,"wires":[]},{"id":"ceceb9d8.c18858","type":"ui_text","z":"9a49eee8.a93ee","group":"6f182569.913e1c","order":4,"width":0,"height":0,"name":"","label":"Reading block: ","format":"{{msg.payload}}","layout":"row-left","x":740,"y":180,"wires":[]},{"id":"e6ed4f92.c07ab","type":"trigger","z":"9a49eee8.a93ee","name":"","op1":"request","op2":"timeout","op1type":"str","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":730,"y":220,"wires":[["de6afc8c.c62dd"]]},{"id":"de6afc8c.c62dd","type":"function","z":"9a49eee8.a93ee","name":"","func":"if(msg.payload == \"request\"){\n return null;\n}else if(msg.payload == \"timeout\"){\n msg.topic =\"error\"\n return msg;\n}\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":900,"y":280,"wires":[["6b54d767.f6fd18"]]},{"id":"9b498cce.cf961","type":"link out","z":"9a49eee8.a93ee","name":"","links":["289af6a5.2334da"],"x":645,"y":480,"wires":[]},{"id":"6b54d767.f6fd18","type":"link out","z":"9a49eee8.a93ee","name":"","links":["289af6a5.2334da"],"x":1015,"y":280,"wires":[]},{"id":"da108f5d.6f0d1","type":"change","z":"9a49eee8.a93ee","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":300,"wires":[["e6ed4f92.c07ab"]]},{"id":"f11c7a7b.b839b8","type":"ui_button","z":"9a49eee8.a93ee","name":"","group":"977b7a3a.0fd208","order":2,"width":0,"height":0,"passthru":false,"label":"Error Codes","tooltip":"Press here to read error codes from the ECU","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":190,"y":560,"wires":[["f4d66684.b85698","988cba06.4a8668"]]},{"id":"f4d66684.b85698","type":"mqtt out","z":"9a49eee8.a93ee","name":"","topic":"/master/app/server/diagnostics/browser/errorreading","qos":"","retain":"","broker":"278f5a97.697a66","x":640,"y":560,"wires":[]},{"id":"b4b193b3.0656b","type":"mqtt in","z":"9a49eee8.a93ee","name":"","topic":"/master/app/server/diagnostics/ecu/errorreading","qos":"2","datatype":"auto","broker":"278f5a97.697a66","x":260,"y":660,"wires":[["fa638387.1557","c46f9c07.db75a"]]},{"id":"fa638387.1557","type":"function","z":"9a49eee8.a93ee","name":"","func":"if(msg.payload == \"error\"){\n return [null, msg];\n}\nreturn [msg, null];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":600,"y":780,"wires":[["a95bb7bd.3260b8"],["e0353736.ea04e8"]]},{"id":"a95bb7bd.3260b8","type":"ui_text","z":"9a49eee8.a93ee","group":"977b7a3a.0fd208","order":3,"width":0,"height":0,"name":"","label":"Found DTCs: ","format":"{{msg.payload}}","layout":"row-center","x":850,"y":780,"wires":[]},{"id":"988cba06.4a8668","type":"trigger","z":"9a49eee8.a93ee","name":"","op1":"request","op2":"timeout","op1type":"str","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":830,"y":660,"wires":[["e3dcadb7.f0b65"]]},{"id":"e3dcadb7.f0b65","type":"function","z":"9a49eee8.a93ee","name":"","func":"if(msg.payload == \"request\"){\n return null;\n}else if(msg.payload == \"timeout\"){\n msg.topic =\"error\"\n return msg;\n}\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":720,"wires":[["27953a49.d1acc6"]]},{"id":"e0353736.ea04e8","type":"link out","z":"9a49eee8.a93ee","name":"","links":["289af6a5.2334da"],"x":735,"y":840,"wires":[]},{"id":"27953a49.d1acc6","type":"link out","z":"9a49eee8.a93ee","name":"","links":["289af6a5.2334da"],"x":875,"y":720,"wires":[]},{"id":"c46f9c07.db75a","type":"change","z":"9a49eee8.a93ee","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":660,"wires":[["988cba06.4a8668"]]},{"id":"40a09146.1092","type":"mqtt out","z":"9a49eee8.a93ee","name":"","topic":"/master/app/server/diagnostics/browser/errordelete","qos":"","retain":"","broker":"278f5a97.697a66","x":610,"y":880,"wires":[]},{"id":"9bfdd63e.c76308","type":"ui_button","z":"9a49eee8.a93ee","name":"","group":"108e7af4.922435","order":2,"width":0,"height":0,"passthru":false,"label":"Delete error codes","tooltip":"Press here to delete error codes from the ECU","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":190,"y":880,"wires":[["40a09146.1092","98ac240c.2de118"]]},{"id":"83e924e2.9a3c28","type":"mqtt in","z":"9a49eee8.a93ee","name":"","topic":"/master/app/server/diagnostics/ecu/errordelete","qos":"2","datatype":"auto","broker":"278f5a97.697a66","x":250,"y":1000,"wires":[["2d2db32d.42ec3c","3154ba7.2708b46"]]},{"id":"3154ba7.2708b46","type":"function","z":"9a49eee8.a93ee","name":"","func":"if(msg.payload == \"error\"){\n var o = {topic: \"error\", payload: \"Failed to delete DTCs\"};\n return [o, msg];\n}\nreturn [msg, null];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":600,"y":1120,"wires":[["9e5a678d.da84a8"],["1b1a4a91.7d9ee5"]]},{"id":"9e5a678d.da84a8","type":"ui_text","z":"9a49eee8.a93ee","group":"108e7af4.922435","order":3,"width":0,"height":0,"name":"","label":"","format":"{{msg.payload}}","layout":"row-center","x":830,"y":1120,"wires":[]},{"id":"98ac240c.2de118","type":"trigger","z":"9a49eee8.a93ee","name":"","op1":"request","op2":"timeout","op1type":"str","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":830,"y":1000,"wires":[["cbfa1b9a.4cbc68"]]},{"id":"cbfa1b9a.4cbc68","type":"function","z":"9a49eee8.a93ee","name":"","func":"if(msg.payload == \"request\"){\n return null;\n}else if(msg.payload == \"timeout\"){\n msg.topic =\"error\";\n msg.payload = \"Failed to delete DTCs\";\n return msg;\n}\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":1060,"wires":[["a00fa8e2.3f1388","9e5a678d.da84a8"]]},{"id":"1b1a4a91.7d9ee5","type":"link out","z":"9a49eee8.a93ee","name":"","links":["289af6a5.2334da"],"x":735,"y":1180,"wires":[]},{"id":"a00fa8e2.3f1388","type":"link out","z":"9a49eee8.a93ee","name":"","links":["289af6a5.2334da"],"x":875,"y":1060,"wires":[]},{"id":"2d2db32d.42ec3c","type":"change","z":"9a49eee8.a93ee","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":1000,"wires":[["98ac240c.2de118"]]},{"id":"c5e1e4fe.264a38","type":"ui_button","z":"9a49eee8.a93ee","name":"","group":"e65127de.646628","order":0,"width":0,"height":0,"passthru":false,"label":"Ignition","tooltip":"","color":"","bgcolor":"orange","icon":"","payload":"","payloadType":"str","topic":"","x":160,"y":1360,"wires":[["21b71d31.e46202"]]},{"id":"21b71d31.e46202","type":"mqtt out","z":"9a49eee8.a93ee","name":"","topic":"/master/app/server/body/browser/ignition","qos":"","retain":"","broker":"278f5a97.697a66","x":460,"y":1360,"wires":[]},{"id":"6f182569.913e1c","type":"ui_group","name":"Block Reading","tab":"775aac30.fb3144","order":2,"disp":true,"width":"6","collapse":false},{"id":"278f5a97.697a66","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"977b7a3a.0fd208","type":"ui_group","name":"DTC reading","tab":"775aac30.fb3144","order":3,"disp":true,"width":"6","collapse":false},{"id":"108e7af4.922435","type":"ui_group","name":"Delete DTCs","tab":"775aac30.fb3144","order":4,"disp":true,"width":"6","collapse":false},{"id":"e65127de.646628","type":"ui_group","name":"Ignition","tab":"423190e5.56565","order":1,"disp":true,"width":"6","collapse":false},{"id":"775aac30.fb3144","type":"ui_tab","name":"Diagnostics","icon":"dashboard","disabled":false,"hidden":false},{"id":"423190e5.56565","type":"ui_tab","name":"Body Control","icon":"dashboard","disabled":false,"hidden":false}] [{"id":"9a49eee8.a93ee","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"6923df5.315752","type":"ui_button","z":"9a49eee8.a93ee","name":"","group":"6f182569.913e1c","order":2,"width":0,"height":0,"passthru":false,"label":"Engine diagnostics","tooltip":"Select the block number & start diagnostics","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":250,"y":140,"wires":[["d2b1345e.189638"]]},{"id":"d2b1345e.189638","type":"ui_text_input","z":"9a49eee8.a93ee","name":"","label":"Block number [1-127]","tooltip":"Select the block number to read","group":"6f182569.913e1c","order":1,"width":0,"height":0,"passthru":false,"mode":"number","delay":"0","topic":"","x":250,"y":200,"wires":[["293414fd.45d3ac"]]},{"id":"922ec540.570c88","type":"mqtt out","z":"9a49eee8.a93ee","name":"","topic":"/master/app/server/diagnostics/browser/blockreading","qos":"","retain":"","broker":"278f5a97.697a66","x":640,"y":120,"wires":[]},{"id":"293414fd.45d3ac","type":"function","z":"9a49eee8.a93ee","name":"","func":"if (msg.payload >= 1 && msg.payload <= 20){\n msg.payload = msg.payload.toString();\n msg.topic = \"ECU request\";\n return [msg, null];\n} else if(msg.payload > 20 && msg.payload <= 127){\n msg.payload = \"ERROR: this car only has 20 groups\";\n msg.topic = \"error\"\n return [null, msg];\n\n}else{\n msg.payload = \"ERROR: number must be between 1-127, was: \" + msg.payload;\n msg.topic = \"error\"\n return [null, msg];\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","x":480,"y":200,"wires":[["922ec540.570c88","ceceb9d8.c18858","e6ed4f92.c07ab"],["e36ef48f.2686d8"]]},{"id":"bb58dd9a.a96a","type":"ui_toast","z":"9a49eee8.a93ee","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":false,"topic":"","name":"","x":710,"y":40,"wires":[]},{"id":"b2a99d47.454e9","type":"function","z":"9a49eee8.a93ee","name":"","func":"if(msg.topic == \"error\"){\n return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":40,"wires":[["bb58dd9a.a96a"]]},{"id":"289af6a5.2334da","type":"link in","z":"9a49eee8.a93ee","name":"","links":["e36ef48f.2686d8","9b498cce.cf961","6b54d767.f6fd18","eb397f32.89c47","e0353736.ea04e8","27953a49.d1acc6","1b1a4a91.7d9ee5","a00fa8e2.3f1388"],"x":75,"y":40,"wires":[["b2a99d47.454e9"]]},{"id":"e36ef48f.2686d8","type":"link out","z":"9a49eee8.a93ee","name":"","links":["289af6a5.2334da"],"x":435,"y":240,"wires":[]},{"id":"6aa2a1d1.42076","type":"mqtt in","z":"9a49eee8.a93ee","name":"","topic":"/master/app/server/diagnostics/ecu/blockreading","qos":"2","datatype":"auto","broker":"278f5a97.697a66","x":280,"y":400,"wires":[["44262ada.4091d4","da108f5d.6f0d1"]]},{"id":"81d4c78c.5ecab8","type":"comment","z":"9a49eee8.a93ee","name":"","info":"ECU sends bunch of data to microC.\nEach block has up to 4 sensors.\nEach sensor send 2 integers.\nData is calculated.\nOutput is 1 string for each sensor.\nData should be sent like:\n\"sensor;data;sensor;data;sensor;data;sensor;data\"\nempty read should be (?)\n","x":340,"y":340,"wires":[]},{"id":"44262ada.4091d4","type":"function","z":"9a49eee8.a93ee","name":"","func":"if(msg.payload == \"timeout\"){\n return [null, null, null, null, msg];\n}\nvar tokens = msg.payload.split(\";\"); // format: int;int;int...\n\nvar o1 = {topic: \" \", payload: \" \"};\nvar o2 = {topic: \" \", payload: \" \"};\nvar o3 = {topic: \" \", payload: \" \"};\nvar o4 = {topic: \" \", payload: \" \"};\n\nvar s1 = {iName: 0, a: 0, b: 0};\nvar s2 = {iName: 0, a: 0, b: 0};\nvar s3 = {iName: 0, a: 0, b: 0};\nvar s4 = {iName: 0, a: 0, b: 0};\n\ns1.iName = tokens[0];\ns1.a = tokens[1];\ns1.b = tokens[2];\n\ns2.iName = tokens[3];\ns2.a = tokens[4];\ns2.b = tokens[5];\n\ns3.iName = tokens[6];\ns3.a = tokens[7];\ns3.b = tokens[8];\n\ns4.iName = tokens[9];\ns4.a = tokens[10];\ns4.b = tokens[11];\n\n/*var o = [msg];\nfor(i=0;i<4;i++){\n var tempMsg = msg;\n tempMsg.topic = tokens[i*2];\n tempMsg.payload = tokens[i*2+1];\n o.push(tempMsg);\n //o.push(msg);\n}*/\nextra = 0;\no1.topic = getName(s1, extra);\no2.topic = getName(s2, extra);\nif(s2.iName == 18)\n if(s3.iName == 18)\n extra = 1;\no3.topic = getName(s3, extra);\nextra = 0;\no4.topic = getName(s4, extra);\no1.payload = calcValue(s1);\no2.payload = calcValue(s2);\no3.payload = calcValue(s3);\no4.payload = calcValue(s4);\nreturn [o1, o2, o3, o4, null];\n//return msg_array;\nfunction getName(d, extra) {\n var i = parseInt(d.iName);\n switch(i){\n case 1 :return (\"Engine Speed \");\n case 2 :return (\"Absolute throttle pos.\");\n case 3 :return (\" \");\n case 4 :return (\" \");\n case 5 :return (\"Coolant temperature \");\n case 6 :return (\"Supply voltage battery\");\n case 7 :return (\"Vehicle speed \");\n case 8 :return (\"Cruise Control \");\n case 9 :return (\" \");\n case 10:return (\" \");\n case 11:return (\" \");\n case 12:return (\" \");\n case 13:return (\" \");\n case 14:return (\" \");\n case 15:return (\"CAN bus status \");\n case 16:return (\"Op. cond./AC speed/AC \");\n case 18:\n if(extra == 1)\n return (\"Manifold Pressure \"); \n return (\"Barometric Pressure \");\n case 19:return (\" \");\n case 20:return (\" \");\n case 21:return (\" \");\n case 22:return (\" \");\n case 23:return (\" \");\n case 24:return (\" \");\n case 25:return (\" \");\n case 26:return (\" \");\n case 27:return (\"Ign. Timing \");\n case 28:return (\" \");\n case 30:return (\" \");\n case 31:return (\" \");\n case 33:return (\"Throttle Position \");\n case 34:return (\" \");\n case 35:return (\"Fuel consumption \");\n case 36:return (\" \");\n case 37:return (\" \");\n case 38:return (\" \");\n case 39:return (\"Inj. Quantity Driver \");\n case 40:return (\" \");\n case 41:return (\" \");\n case 42:return (\" \");\n case 43:return (\" \");\n case 44:return (\" \");\n case 45:return (\" \");\n case 46:return (\" \");\n case 47:return (\" \");\n case 48:return (\" \");\n case 49:return (\"Mass Air Flow \");\n case 50:return (\" \");\n case 51:return (\" \");\n case 52:return (\" \");\n case 53:return (\"Air flow air mass \");\n case 54:return (\" \");\n case 55:return (\" \");\n case 56:return (\" \");\n case 57:return (\" \");\n case 59:return (\" \");\n case 60:return (\" \");\n case 62:return (\" \");\n case 64:return (\" \");\n case 65:return (\" \");\n case 66:return (\" \");\n case 67:return (\" \");\n case 68:return (\" \");\n case 69:return (\" \");\n case 70:return (\" \");\n default:return (\" \");\n }\n}\n//var s1 = {iName: 0, sName: \" \", a: 0, b: 0, s: 0};\nfunction calcValue(d) {\n var i = parseInt(d.iName);\n var a = d.a;\n var b = d.b; //`This is ${soMany} times easier!`\n switch(i){\n case 1 : dat = 0.2*a*b; return(`${dat} rpm `);\n case 2 : dat = a*0.002*b; return(`${dat} %% `);\n case 3 : dat = 0.002*a*b; return(`${dat} Deg `);\n case 4 : dat = abs(b-127)*0.01*a; return(`${dat} ATDC `);\n case 5 : dat = a*(b-100)*0.1; return(`${dat} °C `);\n case 6 : dat = 0.001*a*b; return(`${dat} V `);\n case 7 : dat = 0.01*a*b; return(`${dat} rpm `);\n case 8 : dat = 0.1*a*b; return(`${dat} rpm `);\n case 9 : dat = (b-127)*0.02*a; return(`${dat} rpm `);\n case 10: return (b == 0) ? \"COLD \" : \"WARM \"; \n case 11: dat = 0.0001*a*(b-128)+1; return(`${dat} `);\n case 12: dat = 0.001*a*b; return(`${dat} Ohm `);\n case 13: dat = (b-127)*0.001*a; return(`${dat} mm `);\n case 14: dat = 0.005*a*b; return(`${dat} bar `);\n case 15: dat = 0.01*a*b; return(`${dat} ms `);\n case 18: dat = 0.04*a*b; return(`${dat} mbar `);\n case 19: dat = a*b*0.01; return(`${dat} l `);\n case 20: dat = a*(b-128)/128; return(`${dat} %% `);\n case 21: dat = 0.001*a*b; return(`${dat} V `);\n case 22: dat = 0.001*a*b; return(`${dat} ms `);\n case 23: dat = b/256*a; return(`${dat} %% `);\n case 24: dat = 0.001*a*b; return(`${dat} A `);\n case 25: dat = (b*1.421)+(a/182); return(`${dat} g/s `);\n case 26: dat = b-a; return(`${dat} C `);\n case 27: dat = abs(b-128)*0.01*a; return(`${dat} ° `);\n case 28: dat = b-a; return(`${dat} `);\n case 30: dat = b/12*a; return(`${dat} Deg k/w`);\n case 31: dat = b/2560*a; return(`${dat} °C `);\n case 33: dat = 100*b/a ; return(`${dat} %% `);\n case 34: dat = (b-128)*0.01*a; return(`${dat} kW `);\n case 35: dat = 0.01*a*b; return(`${dat} l/h `);\n case 36: dat = a*2560+b*10; return(`${dat} km `);\n case 37: switch(b){\n case 0: return(`ADP OK (${a},${b})`);\n case 1: return(`ADP RUN (${a},${b})`);\n case 0x10: return(`ADP ERR (${a},${b})`);\n default: return(`ADP (${a},${b})`);\n }break;\n case 38: dat = (b-128)*0.001*a; return(`${dat} Deg k/w`);\n case 39: dat = b/256*a; return(`${dat} mg/h `);\n case 40: dat = b*0.1+(25.5*a)-400; return(`${dat} A `);\n case 41: dat = b+a*255; return(`${dat} Ah `);\n case 42: dat = b*0.1+(25.5*a)-400; return(`${dat} Kw `);\n case 43: dat = b*0.1+(25.5*a); return(`${dat} V `);\n case 44: return(`${a}:${b} `);\n case 45: dat = 0.1*a*b/100; return(`${dat} `);\n case 46: dat = (a*b-3200)*0.0027; return(`${dat} Deg k/w`);\n case 47: dat = (b-128)*a; return(`${dat} ms `);\n case 48: dat = b+a*255; return(`${dat} `);\n case 49: dat = (b/4)*a*0.1; return(`${dat} mg/h `);\n case 50: dat = (b-128)/(0.01*a); return(`${dat} mbar `);\n case 51: dat = ((b-128)/255)*a; return(`${dat} mg/h `);\n case 52: dat = b*0.02*a-a; return(`${dat} Nm `);\n case 53: dat = (b-128)*1.4222+0.006*a; return(`${dat} g/s `);\n case 54: dat = a*256+b; return(`${dat} count `);\n case 55: dat = a*b/200; return(`${dat} s `);\n case 56: dat = a*256+b; return(`${dat} WSC `);\n case 57: dat = a*256+b+65536; return(`${dat} WSC `);\n case 59: dat = (a*256+b)/32768; return(`${dat} g/s `);\n case 60: dat = (a*256+b)*0.01; return(`${dat} sec `);\n case 62: dat = 0.256*a*b; return(`${dat} S `);\n case 64: dat = a+b; return(`${dat} Ohm `);\n case 65: dat = 0.01*a*(b-127); return(`${dat} mm `);\n case 66: dat = (a*b)/511.12; return(`${dat} V `);\n case 67: dat = (640*a)+b*2.5; return(`${dat} Deg `);\n case 68: dat = (256*a+b)/7.365; return(`${dat} deg/s `);\n case 69: dat = (256*a +b)*0.3254; return(`${dat} Bar `);\n case 70: dat = (256*a +b)*0.192; return(`${dat} m/s^2 `);\n default: return(`${a}, ${b} `); \n }\n}\n\n","outputs":5,"noerr":0,"initialize":"","finalize":"","x":560,"y":400,"wires":[["3f9f0d54.9a1862"],["9e7934fe.9e2a18"],["71a11ba1.1d4494"],["67c47310.d092fc"],["9b498cce.cf961"]]},{"id":"3f9f0d54.9a1862","type":"ui_text","z":"9a49eee8.a93ee","group":"6f182569.913e1c","order":6,"width":0,"height":0,"name":"","label":"{{msg.topic}}","format":"{{msg.payload}}","layout":"row-center","x":830,"y":340,"wires":[]},{"id":"9e7934fe.9e2a18","type":"ui_text","z":"9a49eee8.a93ee","group":"6f182569.913e1c","order":7,"width":0,"height":0,"name":"","label":"{{msg.topic}}","format":"{{msg.payload}}","layout":"row-center","x":850,"y":380,"wires":[]},{"id":"71a11ba1.1d4494","type":"ui_text","z":"9a49eee8.a93ee","group":"6f182569.913e1c","order":8,"width":0,"height":0,"name":"","label":"{{msg.topic}}","format":"{{msg.payload}}","layout":"row-center","x":870,"y":420,"wires":[]},{"id":"67c47310.d092fc","type":"ui_text","z":"9a49eee8.a93ee","group":"6f182569.913e1c","order":9,"width":0,"height":0,"name":"","label":"{{msg.topic}}","format":"{{msg.payload}}","layout":"row-center","x":890,"y":460,"wires":[]},{"id":"ceceb9d8.c18858","type":"ui_text","z":"9a49eee8.a93ee","group":"6f182569.913e1c","order":4,"width":0,"height":0,"name":"","label":"Reading block: ","format":"{{msg.payload}}","layout":"row-left","x":740,"y":180,"wires":[]},{"id":"e6ed4f92.c07ab","type":"trigger","z":"9a49eee8.a93ee","name":"","op1":"request","op2":"timeout","op1type":"str","op2type":"str","duration":"30","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":730,"y":220,"wires":[["de6afc8c.c62dd"]]},{"id":"de6afc8c.c62dd","type":"function","z":"9a49eee8.a93ee","name":"","func":"if(msg.payload == \"request\"){\n return null;\n}else if(msg.payload == \"timeout\"){\n msg.topic =\"error\"\n return msg;\n}\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":900,"y":280,"wires":[["6b54d767.f6fd18"]]},{"id":"9b498cce.cf961","type":"link out","z":"9a49eee8.a93ee","name":"","links":["289af6a5.2334da"],"x":645,"y":480,"wires":[]},{"id":"6b54d767.f6fd18","type":"link out","z":"9a49eee8.a93ee","name":"","links":["289af6a5.2334da"],"x":1015,"y":280,"wires":[]},{"id":"da108f5d.6f0d1","type":"change","z":"9a49eee8.a93ee","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":300,"wires":[["e6ed4f92.c07ab"]]},{"id":"f11c7a7b.b839b8","type":"ui_button","z":"9a49eee8.a93ee","name":"","group":"977b7a3a.0fd208","order":2,"width":0,"height":0,"passthru":false,"label":"Error Codes","tooltip":"Press here to read error codes from the ECU","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":190,"y":560,"wires":[["f4d66684.b85698","988cba06.4a8668"]]},{"id":"f4d66684.b85698","type":"mqtt out","z":"9a49eee8.a93ee","name":"","topic":"/master/app/server/diagnostics/browser/errorreading","qos":"","retain":"","broker":"278f5a97.697a66","x":640,"y":560,"wires":[]},{"id":"b4b193b3.0656b","type":"mqtt in","z":"9a49eee8.a93ee","name":"","topic":"/master/app/server/diagnostics/ecu/errorreading","qos":"2","datatype":"auto","broker":"278f5a97.697a66","x":260,"y":660,"wires":[["fa638387.1557","c46f9c07.db75a"]]},{"id":"fa638387.1557","type":"function","z":"9a49eee8.a93ee","name":"","func":"if(msg.payload == \"error\"){\n return [null, msg];\n}\n//return [msg, null];\nvar tokens = msg.payload.split(\";\"); // format: int;int;int...\n\nvar newMsg = {payload: \" \", topic: \"DTCs\"};\n/*if(token[0] == 0){\n newMsg.payload = \"no DTCs found\"\n return [newMsg, null];\n}*/\n//var o1 = {topic: \" \", payload: \" \"};\n\n/*for(var token in tokens){\n newMsg.payload += \"P\";\n newMsg.payload += token;\n newMsg.payload += \"\\n\";\n}*/\nfor (i = 0; i < tokens.length; i++) { //tokens.length-1\n //newMsg.payload += \"00\";\n newMsg.payload += tokens[i];\n newMsg.payload += \" \";\n}\n\n\nreturn [newMsg, null];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":600,"y":780,"wires":[["a95bb7bd.3260b8"],["e0353736.ea04e8"]]},{"id":"a95bb7bd.3260b8","type":"ui_text","z":"9a49eee8.a93ee","group":"977b7a3a.0fd208","order":3,"width":0,"height":0,"name":"","label":"Found DTCs: ","format":"{{msg.payload}}","layout":"row-center","x":850,"y":780,"wires":[]},{"id":"988cba06.4a8668","type":"trigger","z":"9a49eee8.a93ee","name":"","op1":"request","op2":"timeout","op1type":"str","op2type":"str","duration":"30","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":830,"y":660,"wires":[["e3dcadb7.f0b65"]]},{"id":"e3dcadb7.f0b65","type":"function","z":"9a49eee8.a93ee","name":"","func":"if(msg.payload == \"request\"){\n return null;\n}else if(msg.payload == \"timeout\"){\n msg.topic =\"error\"\n return msg;\n}\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":720,"wires":[["27953a49.d1acc6"]]},{"id":"e0353736.ea04e8","type":"link out","z":"9a49eee8.a93ee","name":"","links":["289af6a5.2334da"],"x":735,"y":840,"wires":[]},{"id":"27953a49.d1acc6","type":"link out","z":"9a49eee8.a93ee","name":"","links":["289af6a5.2334da"],"x":875,"y":720,"wires":[]},{"id":"c46f9c07.db75a","type":"change","z":"9a49eee8.a93ee","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":660,"wires":[["988cba06.4a8668"]]},{"id":"40a09146.1092","type":"mqtt out","z":"9a49eee8.a93ee","name":"","topic":"/master/app/server/diagnostics/browser/errordelete","qos":"","retain":"","broker":"278f5a97.697a66","x":610,"y":880,"wires":[]},{"id":"9bfdd63e.c76308","type":"ui_button","z":"9a49eee8.a93ee","name":"","group":"108e7af4.922435","order":2,"width":0,"height":0,"passthru":false,"label":"Delete error codes","tooltip":"Press here to delete error codes from the ECU","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":190,"y":880,"wires":[["40a09146.1092","98ac240c.2de118"]]},{"id":"83e924e2.9a3c28","type":"mqtt in","z":"9a49eee8.a93ee","name":"","topic":"/master/app/server/diagnostics/ecu/errordelete","qos":"2","datatype":"auto","broker":"278f5a97.697a66","x":250,"y":1000,"wires":[["2d2db32d.42ec3c","3154ba7.2708b46"]]},{"id":"3154ba7.2708b46","type":"function","z":"9a49eee8.a93ee","name":"","func":"if(msg.payload == \"error\"){\n var o = {topic: \"error\", payload: \"Failed to delete DTCs\"};\n return [o, msg];\n}\nreturn [msg, null];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":600,"y":1120,"wires":[["9e5a678d.da84a8"],["1b1a4a91.7d9ee5"]]},{"id":"9e5a678d.da84a8","type":"ui_text","z":"9a49eee8.a93ee","group":"108e7af4.922435","order":3,"width":0,"height":0,"name":"","label":"","format":"{{msg.payload}}","layout":"row-center","x":830,"y":1120,"wires":[]},{"id":"98ac240c.2de118","type":"trigger","z":"9a49eee8.a93ee","name":"","op1":"request","op2":"timeout","op1type":"str","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":830,"y":1000,"wires":[["cbfa1b9a.4cbc68"]]},{"id":"cbfa1b9a.4cbc68","type":"function","z":"9a49eee8.a93ee","name":"","func":"if(msg.payload == \"request\"){\n return null;\n}else if(msg.payload == \"timeout\"){\n msg.topic =\"error\";\n msg.payload = \"Failed to delete DTCs\";\n return msg;\n}\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":1060,"wires":[["a00fa8e2.3f1388","9e5a678d.da84a8"]]},{"id":"1b1a4a91.7d9ee5","type":"link out","z":"9a49eee8.a93ee","name":"","links":["289af6a5.2334da"],"x":735,"y":1180,"wires":[]},{"id":"a00fa8e2.3f1388","type":"link out","z":"9a49eee8.a93ee","name":"","links":["289af6a5.2334da"],"x":875,"y":1060,"wires":[]},{"id":"2d2db32d.42ec3c","type":"change","z":"9a49eee8.a93ee","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":1000,"wires":[["98ac240c.2de118"]]},{"id":"c5e1e4fe.264a38","type":"ui_button","z":"9a49eee8.a93ee","name":"","group":"e65127de.646628","order":0,"width":0,"height":0,"passthru":false,"label":"Ignition","tooltip":"","color":"","bgcolor":"orange","icon":"","payload":"","payloadType":"str","topic":"","x":160,"y":1360,"wires":[["21b71d31.e46202"]]},{"id":"21b71d31.e46202","type":"mqtt out","z":"9a49eee8.a93ee","name":"","topic":"/master/app/server/body/browser/ignition","qos":"","retain":"","broker":"278f5a97.697a66","x":460,"y":1360,"wires":[]},{"id":"9af2bbf6.d52e18","type":"ui_button","z":"9a49eee8.a93ee","name":"","group":"7f444e50.6116e","order":0,"width":0,"height":0,"passthru":false,"label":"Clear","tooltip":"","color":"","bgcolor":"","icon":"","payload":" ","payloadType":"str","topic":"","x":1130,"y":720,"wires":[["a95bb7bd.3260b8","67c47310.d092fc","71a11ba1.1d4494","9e7934fe.9e2a18","3f9f0d54.9a1862"]]},{"id":"6f182569.913e1c","type":"ui_group","name":"Block Reading","tab":"775aac30.fb3144","order":2,"disp":true,"width":"6","collapse":false},{"id":"278f5a97.697a66","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"977b7a3a.0fd208","type":"ui_group","name":"DTC reading","tab":"775aac30.fb3144","order":3,"disp":true,"width":"6","collapse":false},{"id":"108e7af4.922435","type":"ui_group","name":"Delete DTCs","tab":"775aac30.fb3144","order":4,"disp":true,"width":"6","collapse":false},{"id":"e65127de.646628","type":"ui_group","name":"Ignition","tab":"423190e5.56565","order":1,"disp":true,"width":"6","collapse":false},{"id":"7f444e50.6116e","type":"ui_group","name":"Default","tab":"3e3302a9.be1cce","order":1,"disp":true,"width":"6","collapse":false},{"id":"775aac30.fb3144","type":"ui_tab","name":"Diagnostics","icon":"dashboard","disabled":false,"hidden":false},{"id":"423190e5.56565","type":"ui_tab","name":"Body Control","icon":"dashboard","disabled":false,"hidden":false},{"id":"3e3302a9.be1cce","type":"ui_tab","name":"Options","icon":"dashboard","disabled":false,"hidden":false}]
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment