i reduced for the main nodes!
[{"id":"b26ad236.0dc21","type":"subflow","name":"Stop Transaction","info":"","in":[{"x":320,"y":160,"wires":[{"id":"16a1a970.cc6777"}]}],"out":[{"x":760,"y":100,"wires":[{"id":"16a1a970.cc6777","port":0}]}]},{"id":"16a1a970.cc6777","type":"function","z":"b26ad236.0dc21","name":"Stop Transaction","func":"var reason = msg.payload.reason\nvar ID = msg.payload.tagid\nvar meter\nvar time \nvar tempo = global.get(\"data\")\nvar TagId = global.get(\"TagId\")\nvar Tablereason = [\n \"EmergencyStop\",\n \"EvDisconnected\",\n \"HardReset\",\n \"Local\",\n \"Other\",\n \"PowerLoss\",\n \"Reboot\",\n \"Remote\",\n \"SoftReset\",\n \"Unlook_Command\",\n \"DeAuthorized\"]\n\nmsg1 = {};\nmsg2 = {};\n\nvar saida = {\n command: \"StopTransaction\",\n data: {\n idTag: ID,\n meterStop: \"1\",\n timestamp:tempo,\n transactionId: \"1\",\n reason: Tablereason[reason]\n \n }\n\n}\nmsg1.payload = saida;\n\nif (reason == 10) {\n msg2.payload = true\n return [msg1,msg2]\n}\nelse {\n return [msg1,null]\n}\n\n","outputs":2,"noerr":0,"x":570,"y":160,"wires":[[],["c3bc1792.c6c5f8"]]},{"id":"fa32409.aeee3c","type":"modbus-read","z":"b26ad236.0dc21","name":"Bt emergĂŞncia","topic":"","showStatusActivities":false,"showErrors":false,"unitid":"1","dataType":"Coil","adr":"403","quantity":"1","rate":"1","rateUnit":"s","delayOnStart":true,"startDelayTime":"2","server":"df796c74.df3f2","useIOFile":false,"ioFile":"","useIOForPayload":false,"x":400,"y":260,"wires":[["edd1aa4b.0773f8"],[]]},{"id":"edd1aa4b.0773f8","type":"function","z":"b26ad236.0dc21","name":"Trata bt EmergĂŞncia","func":"var emergencia = msg.payload [0];\nvar flagStart = global.get(\"flagStart\");\nvar TagId = global.get (\"TagId\");\nvar btemergencia = global.get (\"flagEmergencia\")\nif ((flagStart === true) && (emergencia === false) && (btemergencia === false)){\n global.set(\"flagEmergencia\",true)\n var mensagem = {\n reason: 0,\n tagid: TagId,}\n msg.payload = mensagem\n return msg;\n}\nelse if (emergencia === true) {\n global.set(\"flagEmergencia\",false)\n\n}","outputs":1,"noerr":0,"x":600,"y":260,"wires":[["16a1a970.cc6777"]]},{"id":"c3bc1792.c6c5f8","type":"modbus-write","z":"b26ad236.0dc21","name":"Stop Charge","showStatusActivities":false,"showErrors":false,"unitid":"1","dataType":"Coil","adr":"404","quantity":"1","server":"df796c74.df3f2","x":770,"y":160,"wires":[[],[]]},{"id":"55f15330.8255ac","type":"subflow","name":"Authorization","info":"","in":[{"x":260,"y":60,"wires":[{"id":"22f32865.add528"}]}],"out":[{"x":600,"y":60,"wires":[{"id":"22f32865.add528","port":0}]}]},{"id":"22f32865.add528","type":"function","z":"55f15330.8255ac","name":"F= Athourize","func":"var ID = msg.payload\nmsg1 = {};\nmsg2 = {};\nvar confirma = global.get(\"conf\")\nvar LastId = global.get(\"TagId\")\nvar FlagAutho = global.get (\"flagAutho\")\n\nif (FlagAutho === false){\nif (confirma === true){\nvar auto = {\n command: \"Authorize\",\n data: ID\n}\nmsg1.payload = auto\nreturn [msg1,null];\n}}\nelse {\n if (LastId !== ID){\n var telaErro = true\n msg2.payload = telaErro\n return [null,msg2];\n }\n else {\n var auto = {\n command: \"Authorize\",\n data: ID}\n msg1.payload = auto\nreturn [msg1,null];\n}}","outputs":2,"noerr":0,"x":430,"y":60,"wires":[[],["c8b867d0.817578"]]},{"id":"c8b867d0.817578","type":"modbus-write","z":"55f15330.8255ac","name":"Inicio","showStatusActivities":true,"showErrors":false,"unitid":"1","dataType":"Coil","adr":"402","quantity":"1","server":"df796c74.df3f2","x":630,"y":140,"wires":[[],[]]},{"id":"becbca07.6b7348","type":"subflow","name":"Start Transaction","info":"","in":[{"x":360,"y":120,"wires":[{"id":"4c6ff3f2.08d31c"}]}],"out":[{"x":660,"y":120,"wires":[{"id":"4c6ff3f2.08d31c","port":0}]}]},{"id":"4c6ff3f2.08d31c","type":"function","z":"becbca07.6b7348","name":"Start Transaction","func":"var meter\nvar time \nvar tempo = global.get(\"data\")\nvar ID = global.get(\"IdTag\")\n\nvar saida = {\n command: \"StartTransaction\",\n data: {\n connectorId: \"1\",\n idTag: ID,\n meterStart: \"1\",\n reservationId: \"1\",\n timestamp:tempo\n \n }\n\n}\nmsg.payload = saida\n\nreturn msg;\n","outputs":1,"noerr":0,"x":510,"y":120,"wires":[[]]},{"id":"9254c899.59e018","type":"subflow","name":"RFID","info":"","in":[{"x":240,"y":100,"wires":[{"id":"276ae472.b9ba9c"}]}],"out":[{"x":560,"y":60,"wires":[{"id":"276ae472.b9ba9c","port":0}]},{"x":560,"y":100,"wires":[{"id":"276ae472.b9ba9c","port":1}]}]},{"id":"276ae472.b9ba9c","type":"function","z":"9254c899.59e018","name":"Trata RFID","func":"var ID = msg.payload\nvar flagStart = global.get(\"flagStart\");\nvar TagId = global.get(\"TagId\");\n\nmsg1 = {};\nmsg2 = {};\nmsg3 = {};\nif ((flagStart === true) && (ID == TagId)){\n mensagem = {\n tagid : ID,\n reason: 10\n }\n msg2.payload = mensagem\n // global.set(\"flagTrans\",false)\n return [null,msg2,null];\n}\nelse if ((flagStart === true) && (ID !== TagId)) {\n msg3.payload = true\n return [null,null,msg3];\n}\nelse {\n msg1.payload = ID;\n return [msg1,null,null];\n}","outputs":3,"noerr":0,"x":410,"y":80,"wires":[[],[],["4b4546b7.641dd8"]]},{"id":"4b4546b7.641dd8","type":"modbus-write","z":"9254c899.59e018","name":"Usuario Errado","showStatusActivities":true,"showErrors":false,"unitid":"1","dataType":"Coil","adr":"402","quantity":"1","server":"df796c74.df3f2","x":580,"y":180,"wires":[[],[]]},{"id":"df796c74.df3f2","type":"modbus-client","z":"","name":"IHM","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"tcpHost":"192.168.0.3","tcpPort":"800","tcpType":"TPC-RTU-BUFFERED","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectTimeout":"2000"},{"id":"142b2080.5eb18","type":"subflow:9254c899.59e018","z":"6692752d.2bb74c","name":"","x":230,"y":200,"wires":[["24b7438f.e3580c"],["5cacab98.6025b4"]]},{"id":"b72d1880.7b67c8","type":"subflow:becbca07.6b7348","z":"6692752d.2bb74c","name":"","x":410,"y":120,"wires":[["65477198.529cd"]]},{"id":"24b7438f.e3580c","type":"subflow:55f15330.8255ac","z":"6692752d.2bb74c","name":"","x":400,"y":160,"wires":[["65477198.529cd"]]},{"id":"65477198.529cd","type":"CP client JSON","z":"6692752d.2bb74c","name":"OCPP Client","cbId":"001","remotecs":"9ee4c466.a18728","ocppver":"1.6j","command":"","cmddata":"","log":false,"pathlog":"","x":750,"y":220,"wires":[["f6400f30.d007f"],["902675a1.54ed48"]]},{"id":"f6400f30.d007f","type":"function","z":"6692752d.2bb74c","name":"Resposta OCPP","func":"var command = msg.ocpp.command;\nmsg1={};\nmsg2={};\nmsg3={};\nmsg4={};\nswitch (command){\n \n case \"BootNotification\":\nif (msg.payload.data.status == \"Accepted\"){\nglobal.set(\"interval\",msg.payload.data.interval);\nglobal.set(\"flagBoot\",true);\nglobal.set(\"erro\",20);\n}\nbreak;\n\ncase \"Authorize\":\nvar auto = msg.payload.data.idTagInfo.status\nvar ID = msg.payload.data.idTagInfo.parentIdTag;\n if (auto == (\"Accepted\")){\n global.set(\"flagAutho\",true);\n global.set(\"TagId\",ID)\n msg3.payload = true\n return [msg3,null,null]\n}\n else {\n global.set(\"flagAutho\",false);\n msg2.payload = \"ID Unvalable\"\n return [null,null,msg2]\n }\nbreak;\n\ncase \"StartTransaction\":\n var Trans = msg.payload.data.idTagInfo.status\n var IDT = global.get(\"TagId\")\n var map = Array.prototype.map;\n var ascii = map.call(String(IDT), function(x) { return x.charCodeAt(0); });\n\n if (Trans == (\"Accepted\")){\n global.set(\"flagStart\",true);\n global.set(\"flagStop\",false)\n global.set(\"flag2\",false);\n global.set(\"timeoutStart\",true);\n msg1.payload = true\n msg2.payload = ascii;\n return [null,msg1,msg2];\n}\n else{\n global.set(\"flagStart\",false);\n global.set(\"flag2\",false);\n msg1.payload = false;\n msg2.payload = \"ID unvalable\"\n return [null,msg1,msg2];\n\n}\nbreak;\ncase \"StopTransaction\":\n var Stop = msg.payload.data.idTagInfo.status\n var IDTstop = global.get(\"TagId\")\n if (Stop == \"Accepted\"){\n global.set(\"flagStop\",true)\n global.set(\"flagStart\",false)\n global.set(\"FlagTimer\",false)\n}\nbreak;\ncase \"ChangeConfiguration\":\n var ocppID = msg.ocpp.MessageId\n var Key = msg.payload.data.key\n var Value = msg.payload.data.value\n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n key: Key,\n value: Value\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"CancelReservation\":\n var ocppID = msg.ocpp.MessageId\n var IDreservation = msg.payload.data.reservationId;\n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n ReservationId: IDreservation\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"ChangeAvailability\":\n var ocppID = msg.ocpp.MessageId\n var ConnectorId = msg.payload.data.connectorId;\n var Type = msg.payload.data.type;\n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n connectorId: ConnectorId,\n type:Type,\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"ClearCache\":\n var ocppID = msg.ocpp.MessageId\n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"ClearChargingProfile\":\n var ocppID = msg.ocpp.MessageId\n var Id = msg.payload.data.id;\n var ConnectorId = msg.payload.data.connectorId;\n var ChargingProfilePurpose = msg.payload.data.chargingProfilePurpose;\n var StackLevel = msg.payload.data.stackLevel;\n \n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n id: Id,\n connectorId:ConnectorId,\n chargingProfilePurpose:ChargingProfilePurpose,\n stackLevel: StackLevel,\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"DataTransfer\":\n var ocppID = msg.ocpp.MessageId\n var VendorId = msg.payload.data.vendorId;\n var MessageId = msg.payload.data.messageId;\n var Data = msg.payload.data.data;\n \n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n vendorId: VendorId,\n vessageId:MessageId,\n data:Data,\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"GetCompositeSchedule\":\n var ocppID = msg.ocpp.MessageId\n var ConnectorId = msg.payload.data.connectorId;\n var Duration = msg.payload.data.duration;\n var ChargingRateUnit = msg.payload.data.chargingRateUnit;\n \n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n connectorId:ConnectorId,\n duration:Duration,\n chargingRateUnit:ChargingRateUnit,\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"GetConfiguration\":\n var ocppID = msg.ocpp.MessageId\n var Key = msg.payload.data.key;\n \n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n key:Key,\n }\n return [null,null,null,msg4];\nbreak;\ncase \"GetDiagnostics\":\n var ocppID = msg.ocpp.MessageId;\n var Location = msg.payload.data.location;\n var Retries = msg.payload.data.retries;\n var RetryInterval = msg.payload.data.retryInterval;\n var StartTime = msg.payload.data.startTime;\n var StopTime = msg.payload.data.stopTime;\n \n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n location:Location,\n retries:Retries,\n retryInterval:RetryInterval,\n startTime:StartTime,\n stopTime:StopTime,\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"GetLocalListVersion\":\n var ocppID = msg.ocpp.MessageId\n \n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"RemoteStartTransaction\":\n var ocppID = msg.ocpp.MessageId\n var ConnectorId = msg.payload.data.connectorId;\n var IdTag = msg.payload.data.idTag;\n var ChargingProfile = msg.payload.data.chargingProfile;\n var TransactionId = msg.payload.data.chargingProfile.transactionId;\n var StackLevel = msg.payload.data.chargingProfile.stackLevel;\n var ChargingProfilePurpose= msg.payload.data.chargingProfile.chargingProfilePurpose;\n var ChargingProfileKind= msg.payload.data.chargingProfile.chargingProfileKind;\n var RecurrencyKindd= msg.payload.data.chargingProfile.recurrencyKind;\n var ValidFrom= msg.payload.data.chargingProfile.validFrom;\n var ValidTo= msg.payload.data.chargingProfile.validTo;\n var ChargingSchedule= msg.payload.data.chargingSchedule;\n var Duration= msg.payload.data.chargingProfile.chargingSchedule.duration;\n var StartSchedule= msg.payload.data.chargingProfile.chargingSchedule.startSchedule;\n var ChargingRateUnit= msg.payload.data.chargingProfile.chargingSchedule.chargingRateUnit;\n var ChargingSchedulePeriod= msg.payload.data.chargingProfile.chargingSchedule.chargingSchedulePeriod;\n var MinChargingRate= msg.payload.data.chargingProfile.chargingSchedule.minChargingRate;\n \n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n connectorId:ConnectorId,\n idTag:IdTag,\n chargingProfile:{\n transactionId:TransactionId,\n stackLevel:StackLevel,\n chargingProfilePurpose:ChargingProfilePurpose,\n chargingProfileKind:ChargingProfileKind,\n recurrencyKindd:RecurrencyKindd,\n validFrom:ValidFrom,\n validTo:ValidTo,\n chargingSchedule:{\n duration:Duration,\n startSchedule:StartSchedule,\n chargingRateUnit:ChargingRateUnit,\n chargingSchedulePeriod:ChargingSchedulePeriod,\n minChargingRate:MinChargingRate,\n }}}\n return [null,null,null,msg4];\nbreak;\n\ncase \"RemoteStopTransaction\":\n var ocppID = msg.ocpp.MessageId\n var TransactionId = msg.payload.data.transactionId;\n \n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n transactionId : TransactionId\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"ReserveNow\":\n var ocppID = msg.ocpp.MessageId\n var ConnectorId = msg.payload.data.connectorId;\n var ExpiryDate = msg.payload.data.expiryDate;\n var IdTag = msg.payload.data.idTag;\n var ParentIdTag = msg.payload.data.parentIdTag;\n var ReservationId = msg.payload.data.reservationId;\n \n \n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n connectorId:ConnectorId,\n expiryDate:ExpiryDate,\n idTag:IdTag,\n parentIdTag:ParentIdTag,\n reservationId:ReservationId,\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"Reset\":\n var ocppID = msg.ocpp.MessageId\n var Type = msg.payload.data.type;\n\n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n type:Type,\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"SendLocalList\":\n var ocppID = msg.ocpp.MessageId\n var ListVersion = msg.payload.data.listVersion;\n var LocalAuthorizationList = msg.payload.data.localAuthorizationList;\n var UpdateType = msg.payload.data.updateType;\n \n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n listVersion:ListVersion,\n localAuthorizationList:LocalAuthorizationList,\n updateType:UpdateType,\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"SetChargingProfile\":\n var ocppID = msg.ocpp.MessageId\n var ConnectorId = msg.payload.data.connectorId;\n var CsChargingProfiles = msg.payload.data.csChargingProfiles;\n var TransactionId = msg.payload.data.csChargingProfiles.transactionId;\n var StackLevel = msg.payload.data.csChargingProfiles.stackLevel;\n var ChargingProfilePurpose= msg.payload.data.csChargingProfiles.chargingProfilePurpose;\n var ChargingProfileKind= msg.payload.data.csChargingProfiles.chargingProfileKind;\n var RecurrencyKindd= msg.payload.data.csChargingProfiles.recurrencyKind;\n var ValidFrom= msg.payload.data.csChargingProfiles.validFrom;\n var ValidTo= msg.payload.data.csChargingProfiles.validTo;\n var ChargingSchedule= msg.payload.data.csChargingProfiles.chargingSchedule;\n var Duration= msg.payload.data.csChargingProfiles.chargingSchedule.duration;\n var StartSchedule= msg.payload.data.csChargingProfiles.chargingSchedule.startSchedule;\n var ChargingRateUnit= msg.payload.data.csChargingProfiles.chargingSchedule.chargingRateUnit;\n var ChargingSchedulePeriod= msg.payload.data.csChargingProfiles.chargingSchedule.chargingSchedulePeriod;\n var MinChargingRate= msg.payload.data.csChargingProfiles.chargingSchedule.minChargingRate;\n \n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n connectorId:ConnectorId,\n csChargingProfiles:{\n transactionId:TransactionId,\n stackLevel:StackLevel,\n chargingProfilePurpose:ChargingProfilePurpose,\n chargingProfileKind:ChargingProfileKind,\n recurrencyKindd:RecurrencyKindd,\n validFrom:ValidFrom,\n validTo:ValidTo,\n chargingSchedule:{\n duration:Duration,\n startSchedule:StartSchedule,\n chargingRateUnit:ChargingRateUnit,\n chargingSchedulePeriod:ChargingSchedulePeriod,\n minChargingRate:MinChargingRate,\n }}}\n return [null,null,null,msg4];\nbreak;\n\ncase \"TriggerMessage\":\n var ocppID = msg.ocpp.MessageId\n var RequestedMessage = msg.payload.data.requestedMessage;\n var ConnectorId = msg.payload.data.connectorId;\n \n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n requestedMessage:RequestedMessage,\n connectorId:ConnectorId,\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"UnlockConnector\":\n var ocppID = msg.ocpp.MessageId\n var connectorId = msg.payload.data.connectorId;\n \n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n connectorId:ConnectorId,\n }\n return [null,null,null,msg4];\nbreak;\n\ncase \"UpdateFirmware\":\n var ocppID = msg.ocpp.MessageId\n var Location = msg.payload.data.location;\n var Retries = msg.payload.data.retries;\n var RetrieveDate = msg.payload.data.retrieveDate;\n var RetryInterval = msg.payload.data.retryInterval;\n \n msg4.payload = {\n ID:ocppID,\n OcppCommand:command,\n location:Location,\n retries:Retries,\n retrieveDate:RetrieveDate,\n retryInterval:RetryInterval\n }\n return [null,null,null,msg4];\nbreak\n}\n","outputs":4,"noerr":0,"x":1070,"y":200,"wires":[["b72d1880.7b67c8"],["3c217f35.fa6f2"],["b336b5bc.283fe8"],["8aefd191.eb67d"]]},{"id":"3c217f35.fa6f2","type":"modbus-write","z":"6692752d.2bb74c","name":"Inicio","showStatusActivities":true,"showErrors":false,"unitid":"1","dataType":"Coil","adr":"400","quantity":"1","server":"df796c74.df3f2","x":1250,"y":160,"wires":[[],[]]},{"id":"b336b5bc.283fe8","type":"modbus-write","z":"6692752d.2bb74c","name":"Usuario HMI","showStatusActivities":true,"showErrors":false,"unitid":"1","dataType":"MHoldingRegisters","adr":"400","quantity":"8","server":"df796c74.df3f2","x":1270,"y":200,"wires":[[],[]]},{"id":"5cacab98.6025b4","type":"subflow:b26ad236.0dc21","z":"6692752d.2bb74c","name":"Stop Transaction","x":410,"y":200,"wires":[["65477198.529cd"]]},{"id":"bb95af16.ca4e8","type":"inject","z":"6692752d.2bb74c","name":"ID","topic":"","payload":"010203AB","payloadType":"global","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":180,"wires":[["142b2080.5eb18"]]},{"id":"9ee4c466.a18728","type":"ocpp-remote-cs","z":"","name":"ocpp","url":"$(URLOCPP)"}]