Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.69 KB | None | 0 0
  1. //Includes
  2. #include <ESP8266WiFi.h>
  3. //#include <WiFiClient.h>
  4. #include <ESP8266WebServer.h>
  5. #include <SimpleModbusMaster.h>
  6. #include <PubSubClient.h>
  7.  
  8.  
  9. //Modbus Config
  10. #define TxEnablePin D3 // RS485 modbus direction control pin:
  11. #define baud 9600 // modbus port speed:
  12. #define timeout 2000 // modbus timeout in mSec:
  13. #define polling 1000 // modbus scan rate in mSec:
  14. #define retry_count 0
  15. #define TOTAL_NO_OF_REGISTERS 400 // number of registers to poll for:
  16.  
  17. //Network settings for client and server
  18. const char* ssid = "linksys"; // SSID des vorhandenen WLANs
  19. const char* password = "qwertzuiopasdfghjkl"; // Passwort für das vorhandene WLAN
  20. const char* mqtt_server = "192.168.1.16";
  21.  
  22. WiFiClient espClient;
  23. PubSubClient client(espClient);
  24. long lastMsg = 0;
  25. char msg[50];
  26. int value = 0;
  27.  
  28.  
  29. IPAddress gateway(192, 168, 1, 1); // IP-Adresse des WLAN-Gateways
  30. IPAddress subnet(255, 255, 255, 0); // Subnetzmaske
  31. IPAddress ip(192, 168, 1, 160); // feste IP-Adresse für den WeMos
  32. ESP8266WebServer server(80); // Webserver initialisieren auf Port 80
  33.  
  34.  
  35. //Variables SDM630
  36. float L1_N;
  37. float L2_N;
  38. float L3_N;
  39. float Strom_L1;
  40. float Strom_L2;
  41. float Strom_L3;
  42. float Watt_L1;
  43. float Watt_L2;
  44. float Watt_L3;
  45. float VA_L1;
  46. float VA_L2;
  47. float VA_L3;
  48. float VAR_L1;
  49. float VAR_L2;
  50. float VAR_L3;
  51. float Powerfactor_L1;
  52. float Powerfactor_L2;
  53. float Powerfactor_L3;
  54. float Phasenwinkel_L1;
  55. float Phasenwinkel_L2;
  56. float Phasenwinkel_L3;
  57. float Average_line_to_neutral_volts;
  58. float Average_line_current;
  59. float Sum_of_line_currents;
  60. float Total_System_Power;
  61. float Total_system_volt_amps;
  62. float Total_system_VAr;
  63. float Total_system_power_factor;
  64. float Total_system_phase_angle;
  65. float Netzfrequenz;
  66. float Total_system_VA_demand;
  67. float Neutral_current_demand;
  68. float Maximum_neutral_current_demand;
  69. float Line1_to_Line2_volts;
  70. float Line2_to_Line3_volts;
  71. float Line3_to_Line1_volts;
  72. float Neutral_current;
  73. float Total_KWh;
  74. float Total_KVArh;
  75. float L1_import_KWh;
  76. float L2_import_KWh;
  77. float L3_import_KWh;
  78. float L1_export_KWh;
  79. float L2_export_KWh;
  80. float L3_export_KWh;
  81. float L1_total_KWh;
  82. float L2_total_KWh;
  83. float L3_total_KWh;
  84. float L1_import_KVArh;
  85. float L2_import_KVArh;
  86. float L3_import_KVArh;
  87. float L1_export_KVArh;
  88. float L2_export_KVArh;
  89. float L3_export_KVArh;
  90. float L1_total_KVArh;
  91. float L2_total_KVArh;
  92. float L3_total_KVArh;
  93.  
  94.  
  95.  
  96.  
  97. enum
  98. {
  99. PACKET1,
  100. PACKET2,
  101. PACKET3,
  102. PACKET4,
  103. PACKET5,
  104. PACKET6,
  105. PACKET7,
  106. PACKET8,
  107. PACKET9,
  108. PACKET10,
  109. PACKET11,
  110. PACKET12,
  111. PACKET13,
  112. PACKET14,
  113. TOTAL_NO_OF_PACKETS // leave this last entry
  114. };
  115. Packet packets[TOTAL_NO_OF_PACKETS]; // array of Packets to be configured
  116.  
  117. //Modbus Variables
  118. unsigned int regs[TOTAL_NO_OF_REGISTERS]; // master register array
  119. long previousMillis = 0;
  120. long interval = 30000;
  121. unsigned long currentMillis;
  122.  
  123. //Webpage Variables
  124. char ConnectString[255] = "";
  125. String Antwort = "";
  126.  
  127. //Start WiFi connection
  128. void WLANVerbindung()
  129. {
  130. // WLAN-Verbindung herstellen
  131. WiFi.config(ip, gateway, subnet); // auskommentieren, falls eine dynamische IP bezogen werden soll
  132. WiFi.begin(ssid, password);
  133. Serial.print("Verbindungsaufbau");
  134.  
  135. Serial.println(" erfolgreich!");
  136. Serial.println("");
  137. Serial.print("Verbunden mit: ");
  138. Serial.println(ssid);
  139. Serial.print("Signalstaerke: ");
  140. int rssi = WiFi.RSSI();
  141. Serial.print(rssi);
  142. Serial.println(" dBm");
  143. Serial.print("IP-Adresse: ");
  144. Serial.println(WiFi.localIP());
  145. Serial.println("");
  146.  
  147. sprintf(ConnectString, "</br></br>Verbunden mit: %s </br>Signalstaerke: %d dBm </br></br>", ssid, rssi);
  148.  
  149. server.on("/", Hauptseite);
  150.  
  151. // HTTP-Server starten
  152. server.begin();
  153. }
  154.  
  155. //Build Webpage content
  156. void Hauptseite()
  157. {
  158. //Reset Antwort
  159. Antwort = "";
  160. Antwort += "<meta http-equiv='refresh' content='60'/>";
  161. Antwort += ConnectString;
  162. Antwort += "<html><body bgcolor='#CCC'>";
  163.  
  164.  
  165. String Nothing = "";
  166.  
  167.  
  168. Antwort += ZeigeWertOnline("L1_N", L1_N, 2, "V");
  169. Antwort += ZeigeWertOnline("L2_N", L2_N, 2, "V");
  170. Antwort += ZeigeWertOnline("L3_N", L3_N, 2, "V");
  171.  
  172. Antwort += ZeigeWertOnline("Strom_L1", Strom_L1, 3, "A");
  173. Antwort += ZeigeWertOnline("Strom_L2", Strom_L2, 3, "A");
  174. Antwort += ZeigeWertOnline("Strom_L3", Strom_L3, 3, "A");
  175.  
  176. Antwort += ZeigeWertOnline("Watt_L1", Watt_L1, 2, "W");
  177. Antwort += ZeigeWertOnline("Watt_L2", Watt_L2, 2, "W");
  178. Antwort += ZeigeWertOnline("Watt_L3", Watt_L3, 2, "W");
  179.  
  180. Antwort += ZeigeWertOnline("VA_L1", VA_L1, 2, "W");
  181. Antwort += ZeigeWertOnline("VA_L2", VA_L2, 2, "W");
  182. Antwort += ZeigeWertOnline("VA_L3", VA_L3, 2, "W");
  183.  
  184. Antwort += ZeigeWertOnline("VAR_L1", VAR_L1, 2, "VAr");
  185. Antwort += ZeigeWertOnline("VAR_L2", VAR_L2, 2, "VAr");
  186. Antwort += ZeigeWertOnline("VAR_L3", VAR_L3, 2, "VAr");
  187.  
  188. Antwort += ZeigeWertOnline("Powerfactor_L1", Powerfactor_L1, 3, " ");
  189. Antwort += ZeigeWertOnline("Powerfactor_L2", Powerfactor_L2, 3, " ");
  190. Antwort += ZeigeWertOnline("Powerfactor_L3", Powerfactor_L3, 3, " ");
  191.  
  192. Antwort += ZeigeWertOnline("Phasenwinkel_L1", Phasenwinkel_L1, 3, " ");
  193. Antwort += ZeigeWertOnline("Phasenwinkel_L2", Phasenwinkel_L2, 3, " ");
  194. Antwort += ZeigeWertOnline("Phasenwinkel_L3", Phasenwinkel_L3, 3, " ");
  195.  
  196. Antwort += ZeigeWertOnline("Average_line_to_neutral_volts", Average_line_to_neutral_volts, 3, " ");
  197. Antwort += ZeigeWertOnline("Average_line_current", Average_line_current, 2, " ");
  198. Antwort += ZeigeWertOnline("Sum_of_line currents", Sum_of_line_currents, 2, " ");
  199. Antwort += ZeigeWertOnline("Total_System_Power", Total_System_Power, 2, " ");
  200.  
  201. Antwort += ZeigeWertOnline("Total_system_volt_amps", Total_system_volt_amps , 2, " ");
  202. Antwort += ZeigeWertOnline("Total_system_VAr", Total_system_VAr , 2, " ");
  203. Antwort += ZeigeWertOnline("Total_system_power_factor", Total_system_power_factor , 2, " ");
  204. Antwort += ZeigeWertOnline("Total_system_phase_angle", Total_system_phase_angle , 2, " ");
  205. Antwort += ZeigeWertOnline("Netzfrequenz", Netzfrequenz , 2, " ");
  206. Antwort += ZeigeWertOnline("Total_system_VA_demand", Total_system_VA_demand , 2, " ");
  207. Antwort += ZeigeWertOnline("Neutral_current_demand", Neutral_current_demand , 2, " ");
  208. Antwort += ZeigeWertOnline("Maximum_neutral_current_demand", Maximum_neutral_current_demand , 2, " ");
  209. Antwort += ZeigeWertOnline("Line1_to_Line2_volts", Line1_to_Line2_volts , 2, " ");
  210. Antwort += ZeigeWertOnline("Line2_to_Line3_volts", Line2_to_Line3_volts , 2, " ");
  211. Antwort += ZeigeWertOnline("Line3_to_Line1_volts", Line3_to_Line1_volts , 2, " ");
  212. Antwort += ZeigeWertOnline("Neutral_current", Neutral_current , 2, " ");
  213. Antwort += ZeigeWertOnline("Total_KWh", Total_KWh , 2, " ");
  214. Antwort += ZeigeWertOnline("Total_KVArh", Total_KVArh , 2, " ");
  215. Antwort += ZeigeWertOnline("L1_import_KWh", L1_import_KWh , 2, " ");
  216. Antwort += ZeigeWertOnline("L2_import_KWh", L2_import_KWh , 2, " ");
  217. Antwort += ZeigeWertOnline("L3_import_KWh", L3_import_KWh , 2, " ");
  218. Antwort += ZeigeWertOnline("L3_import_KWh", L3_import_KWh , 2, " ");
  219. Antwort += ZeigeWertOnline("L1_export_KWh", L1_export_KWh , 2, " ");
  220. Antwort += ZeigeWertOnline("L2_export_KWh", L2_export_KWh , 2, " ");
  221. Antwort += ZeigeWertOnline("L3_export_KWh", L3_export_KWh , 2, " ");
  222. Antwort += ZeigeWertOnline("L1_total_KWh", L1_total_KWh , 2, " ");
  223. Antwort += ZeigeWertOnline("L2_total_KWh", L2_total_KWh , 2, " ");
  224. Antwort += ZeigeWertOnline("L3_total_KWh", L3_total_KWh , 2, " ");
  225. Antwort += ZeigeWertOnline("L1_import_KVArh", L1_import_KVArh , 2, " ");
  226. Antwort += ZeigeWertOnline("L2_import_KVArh", L2_import_KVArh , 2, " ");
  227. Antwort += ZeigeWertOnline("L3_import_KVArh", L3_import_KVArh , 2, " ");
  228. Antwort += ZeigeWertOnline("L1_export_KVArh", L1_export_KVArh , 2, " ");
  229. Antwort += ZeigeWertOnline("L2_export_KVArh", L2_export_KVArh , 2, " ");
  230. Antwort += ZeigeWertOnline("L3_export_KVArh", L3_export_KVArh , 2, " ");
  231. Antwort += ZeigeWertOnline("L3_export_KVArh", L3_export_KVArh , 2, " ");
  232. Antwort += ZeigeWertOnline("L1_total_KVArh", L1_total_KVArh , 2, " ");
  233. Antwort += ZeigeWertOnline("L2_total_KVArh", L2_total_KVArh , 2, " ");
  234. Antwort += ZeigeWertOnline("L3_total_KVArh", L3_total_KVArh , 2, " ");
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241. //Packet Infos
  242. Antwort += String("</br>Requests: ");
  243. Antwort += String(packets[PACKET1].requests);
  244. Antwort += String("</br>Successful Requests: ");
  245. Antwort += String(packets[PACKET1].successful_requests);
  246. Antwort += String("</br>Failed Requests: ");
  247. Antwort += String(packets[PACKET1].failed_requests);
  248. Antwort += String("</br>Exception Errors: ");
  249. Antwort += String(packets[PACKET1].exception_errors);
  250.  
  251. Antwort += String("</br>Requests: ");
  252. Antwort += String(packets[PACKET2].requests);
  253. Antwort += String("</br>Successful Requests: ");
  254. Antwort += String(packets[PACKET2].successful_requests);
  255. Antwort += String("</br>Failed Requests: ");
  256. Antwort += String(packets[PACKET2].failed_requests);
  257. Antwort += String("</br>Exception Errors: ");
  258. Antwort += String(packets[PACKET2].exception_errors);
  259.  
  260. Antwort += String("</br>Requests: ");
  261. Antwort += String(packets[PACKET9].requests);
  262. Antwort += String("</br>Successful Requests: ");
  263. Antwort += String(packets[PACKET9].successful_requests);
  264. Antwort += String("</br>Failed Requests: ");
  265. Antwort += String(packets[PACKET9].failed_requests);
  266. Antwort += String("</br>Exception Errors: ");
  267. Antwort += String(packets[PACKET9].exception_errors);
  268.  
  269.  
  270.  
  271. Antwort += "</body></html>";
  272. server.send ( 300, "text/html", Antwort );
  273. delay(100);
  274.  
  275. //server.send(300, "text/plain", Antwort);
  276. //delay(150);
  277. }
  278. String ZeigeWertOnline(String Text, float WertFloat, int decimals, String Einheit)
  279. {
  280. return String(Text + ": " + String(WertFloat, decimals) + Einheit + "</br>");
  281. }
  282.  
  283.  
  284.  
  285. void callback(char* topic, byte* payload, unsigned int length) {
  286. Serial.print("Message arrived [");
  287. Serial.print(topic);
  288. Serial.print("] ");
  289. for (int i = 0; i < length; i++) {
  290. Serial.print((char)payload[i]);
  291. }
  292. Serial.println();
  293.  
  294. // Switch on the LED if an 1 was received as first character
  295. if ((char)payload[0] == '1') {
  296. digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level
  297. // but actually the LED is on; this is because
  298. // it is active low on the ESP-01)
  299. } else {
  300. digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH
  301. }
  302.  
  303. }
  304.  
  305. void reconnect() {
  306. // Loop until we're reconnected
  307. while (!client.connected()) {
  308. Serial.print("Attempting MQTT connection...");
  309. // Create a random client ID
  310. String clientId = "ESP8266Client-";
  311. clientId += String(random(0xffff), HEX);
  312. // Attempt to connect
  313. if (client.connect(clientId.c_str())) {
  314. Serial.println("connected");
  315. // Once connected, publish an announcement...
  316. client.publish("outTopic", "hello world");
  317. // ... and resubscribe
  318. client.subscribe("inTopic");
  319. } else {
  320. Serial.print("failed, rc=");
  321. Serial.print(client.state());
  322. Serial.println(" try again in 5 seconds");
  323. // Wait 5 seconds before retrying
  324. delay(5000);
  325. }
  326. }
  327. }
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336. //Software setup
  337. void setup()
  338. {
  339. client.setServer(mqtt_server, 1883);
  340. client.setCallback(callback);
  341.  
  342.  
  343. modbus_construct(&packets[PACKET1], 1, READ_INPUT_REGISTERS, 0, 20, 0); // initialize packet 1:
  344. modbus_construct(&packets[PACKET2], 1, READ_INPUT_REGISTERS, 20, 22, 20 ); // initialize packet 2:
  345. modbus_construct(&packets[PACKET3], 1, READ_INPUT_REGISTERS, 46, 4, 46 ); // initialize packet 3:
  346. modbus_construct(&packets[PACKET4], 1, READ_INPUT_REGISTERS, 52, 2, 52 ); // initialize packet 4:
  347. modbus_construct(&packets[PACKET5], 1, READ_INPUT_REGISTERS, 56, 2, 56 ); // initialize packet 5:
  348. modbus_construct(&packets[PACKET6], 1, READ_INPUT_REGISTERS, 60, 4, 60 ); // initialize packet 6:
  349. modbus_construct(&packets[PACKET7], 1, READ_INPUT_REGISTERS, 66, 2, 66 ); // initialize packet 7:
  350. modbus_construct(&packets[PACKET8], 1, READ_INPUT_REGISTERS, 70, 2, 70 ); // initialize packet 8:
  351. modbus_construct(&packets[PACKET9], 1, READ_INPUT_REGISTERS, 100, 2, 100 ); // initialize packet 9:
  352. modbus_construct(&packets[PACKET10], 1, READ_INPUT_REGISTERS, 104, 4, 104 ); // initialize packet 10:
  353. modbus_construct(&packets[PACKET11], 1, READ_INPUT_REGISTERS, 200, 6, 200 ); // initialize packet 11:
  354. modbus_construct(&packets[PACKET12], 1, READ_INPUT_REGISTERS, 224, 2, 224 ); // initialize packet 12:
  355. modbus_construct(&packets[PACKET13], 1, READ_INPUT_REGISTERS, 342, 20, 342 ); // initialize packet 13:
  356. modbus_construct(&packets[PACKET14], 1, READ_INPUT_REGISTERS, 362, 20, 362 ); // initialize packet 14:
  357.  
  358. modbus_configure(&Serial, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
  359.  
  360. delay(100);
  361. WLANVerbindung();
  362.  
  363. WiFi.mode(WIFI_STA);
  364. }
  365.  
  366.  
  367.  
  368.  
  369. //Loop
  370. void loop()
  371. {
  372.  
  373. if (!client.connected()) {
  374. reconnect();
  375. }
  376.  
  377.  
  378. client.loop();
  379.  
  380. long now = millis();
  381. if (now - lastMsg > 2000) {
  382. lastMsg = now;
  383. ++value;
  384. snprintf (msg, 50, "hello world #%ld", value);
  385. Serial.print("Publish message: ");
  386. Serial.println(msg);
  387. client.publish("outTopic", msg);
  388. }
  389.  
  390.  
  391. //Modbus Update
  392. modbus_update();
  393.  
  394. //Handle client requests
  395. server.handleClient(); // auf HTTP-Anfragen warten
  396.  
  397. //Calculate SDM360 Vars
  398. unsigned long temp1 = (unsigned long) regs[0] << 16 | regs[1];
  399. unsigned long temp2 = (unsigned long) regs[2] << 16 | regs[3];
  400. unsigned long temp3 = (unsigned long) regs[4] << 16 | regs[5];
  401. unsigned long temp4 = (unsigned long) regs[6] << 16 | regs[7];
  402. unsigned long temp5 = (unsigned long) regs[8] << 16 | regs[9];
  403. unsigned long temp6 = (unsigned long) regs[10] << 16 | regs[11];
  404. unsigned long temp7 = (unsigned long) regs[12] << 16 | regs[13];
  405. unsigned long temp8 = (unsigned long) regs[14] << 16 | regs[15];
  406. unsigned long temp9 = (unsigned long) regs[16] << 16 | regs[17];
  407. unsigned long temp10 = (unsigned long) regs[18] << 16 | regs[19];
  408. unsigned long temp11 = (unsigned long) regs[20] << 16 | regs[21];
  409. unsigned long temp12 = (unsigned long) regs[22] << 16 | regs[23];
  410. unsigned long temp13 = (unsigned long) regs[24] << 16 | regs[25];
  411. unsigned long temp14 = (unsigned long) regs[26] << 16 | regs[27];
  412. unsigned long temp15 = (unsigned long) regs[28] << 16 | regs[29];
  413. unsigned long temp16 = (unsigned long) regs[30] << 16 | regs[31];
  414. unsigned long temp17 = (unsigned long) regs[32] << 16 | regs[33];
  415. unsigned long temp18 = (unsigned long) regs[34] << 16 | regs[35];
  416. unsigned long temp19 = (unsigned long) regs[36] << 16 | regs[37];
  417. unsigned long temp20 = (unsigned long) regs[38] << 16 | regs[39];
  418. unsigned long temp21 = (unsigned long) regs[40] << 16 | regs[41];
  419. unsigned long temp22 = (unsigned long) regs[42] << 16 | regs[43];
  420.  
  421. unsigned long temp23 = (unsigned long) regs[46] << 16 | regs[47];
  422. unsigned long temp24 = (unsigned long) regs[48] << 16 | regs[49];
  423. unsigned long temp25 = (unsigned long) regs[52] << 16 | regs[53];
  424. unsigned long temp26 = (unsigned long) regs[56] << 16 | regs[57];
  425. unsigned long temp27 = (unsigned long) regs[60] << 16 | regs[61];
  426. unsigned long temp28 = (unsigned long) regs[62] << 16 | regs[63];
  427. unsigned long temp29 = (unsigned long) regs[66] << 16 | regs[67];
  428. unsigned long temp30 = (unsigned long) regs[70] << 16 | regs[71];
  429. unsigned long temp31 = (unsigned long) regs[100] << 16 | regs[101];
  430. unsigned long temp32 = (unsigned long) regs[104] << 16 | regs[105];
  431. unsigned long temp33 = (unsigned long) regs[106] << 16 | regs[107];
  432. unsigned long temp34 = (unsigned long) regs[200] << 16 | regs[201];
  433. unsigned long temp35 = (unsigned long) regs[202] << 16 | regs[203];
  434. unsigned long temp36 = (unsigned long) regs[204] << 16 | regs[205];
  435. unsigned long temp37 = (unsigned long) regs[224] << 16 | regs[225];
  436. unsigned long temp38 = (unsigned long) regs[342] << 16 | regs[343];
  437. unsigned long temp39 = (unsigned long) regs[344] << 16 | regs[345];
  438. unsigned long temp40 = (unsigned long) regs[346] << 16 | regs[347];
  439. unsigned long temp41 = (unsigned long) regs[348] << 16 | regs[349];
  440. unsigned long temp42 = (unsigned long) regs[350] << 16 | regs[351];
  441. unsigned long temp43 = (unsigned long) regs[352] << 16 | regs[353];
  442. unsigned long temp44 = (unsigned long) regs[354] << 16 | regs[355];
  443. unsigned long temp45 = (unsigned long) regs[356] << 16 | regs[357];
  444. unsigned long temp46 = (unsigned long) regs[358] << 16 | regs[359];
  445. unsigned long temp47 = (unsigned long) regs[360] << 16 | regs[361];
  446. unsigned long temp48 = (unsigned long) regs[362] << 16 | regs[363];
  447. unsigned long temp49 = (unsigned long) regs[364] << 16 | regs[365];
  448. unsigned long temp50 = (unsigned long) regs[366] << 16 | regs[367];
  449. unsigned long temp51 = (unsigned long) regs[368] << 16 | regs[369];
  450. unsigned long temp52 = (unsigned long) regs[370] << 16 | regs[371];
  451. unsigned long temp53 = (unsigned long) regs[372] << 16 | regs[373];
  452. unsigned long temp54 = (unsigned long) regs[374] << 16 | regs[375];
  453. unsigned long temp55 = (unsigned long) regs[376] << 16 | regs[377];
  454. unsigned long temp56 = (unsigned long) regs[378] << 16 | regs[379];
  455. unsigned long temp57 = (unsigned long) regs[380] << 16 | regs[381];
  456.  
  457.  
  458.  
  459. L1_N = *(float*)&temp1;
  460. L2_N = *(float*)&temp2;
  461. L3_N = *(float*)&temp3;
  462. Strom_L1 = *(float*)&temp4;
  463. Strom_L2 = *(float*)&temp5;
  464. Strom_L3 = *(float*)&temp6;
  465. Watt_L1 = *(float*)&temp7;
  466. Watt_L2 = *(float*)&temp8;
  467. Watt_L3 = *(float*)&temp9;
  468. VA_L1 = *(float*)&temp10;
  469. VA_L2 = *(float*)&temp11;
  470. VA_L3 = *(float*)&temp12;
  471. VAR_L1 = *(float*)&temp13;
  472. VAR_L2 = *(float*)&temp14;
  473. VAR_L3 = *(float*)&temp15;
  474. Powerfactor_L1 = *(float*)&temp16;
  475. Powerfactor_L2 = *(float*)&temp17;
  476. Powerfactor_L3 = *(float*)&temp18;
  477. Phasenwinkel_L1 = *(float*)&temp19;
  478. Phasenwinkel_L2 = *(float*)&temp20;
  479. Phasenwinkel_L3 = *(float*)&temp21;
  480. Average_line_to_neutral_volts = *(float*)&temp22;
  481. Average_line_current = *(float*)&temp23;
  482. Sum_of_line_currents = *(float*)&temp24;
  483. Total_System_Power = *(float*)&temp25;
  484. Total_system_volt_amps = *(float*)&temp26;
  485. Total_system_VAr = *(float*)&temp27;
  486. Total_system_power_factor = *(float*)&temp28;
  487. Total_system_phase_angle = *(float*)&temp29;
  488. Netzfrequenz = *(float*)&temp30;
  489. Total_system_VA_demand = *(float*)&temp31;
  490. Neutral_current_demand = *(float*)&temp32;
  491. Maximum_neutral_current_demand = *(float*)&temp33;
  492. Line1_to_Line2_volts = *(float*)&temp34;
  493. Line2_to_Line3_volts = *(float*)&temp35;
  494. Line3_to_Line1_volts = *(float*)&temp36;
  495. Neutral_current = *(float*)&temp37;
  496. Total_KWh = *(float*)&temp38;
  497. Total_KVArh = *(float*)&temp39;
  498. L1_import_KWh = *(float*)&temp40;
  499. L2_import_KWh = *(float*)&temp41;
  500. L3_import_KWh = *(float*)&temp42;
  501. L1_export_KWh = *(float*)&temp43;
  502. L2_export_KWh = *(float*)&temp44;
  503. L3_export_KWh = *(float*)&temp45;
  504. L1_total_KWh = *(float*)&temp46;
  505. L2_total_KWh = *(float*)&temp47;
  506. L3_total_KWh = *(float*)&temp48;
  507. L1_import_KVArh = *(float*)&temp49;
  508. L2_import_KVArh = *(float*)&temp50;
  509. L3_import_KVArh = *(float*)&temp51;
  510. L1_export_KVArh = *(float*)&temp52;
  511. L2_export_KVArh = *(float*)&temp53;
  512. L3_export_KVArh = *(float*)&temp54;
  513. L1_total_KVArh = *(float*)&temp55;
  514. L2_total_KVArh = *(float*)&temp56;
  515. L3_total_KVArh = *(float*)&temp57;
  516.  
  517.  
  518.  
  519. //Update
  520. //entfernt currentMillis = millis();
  521. //entfernt if (currentMillis - previousMillis >= interval)
  522. //entfernt {
  523. //entfernt MeldeWert("L1_N", L1_N); //Hier werden die Daten an die CCU geschickt
  524. //entfernt MeldeWert("L2_N", L2_N);
  525. //entfernt MeldeWert("L3_N", L3_N);
  526. //entfernt MeldeWert("Strom_L1", Strom_L1);
  527. //entfernt MeldeWert("Strom_L2", Strom_L2);
  528. //entfernt MeldeWert("Strom_L3", Strom_L3);
  529. //entfernt MeldeWert("Watt_L1", Watt_L1);
  530. //entfernt MeldeWert("Watt_L2", Watt_L2);
  531. //entfernt MeldeWert("Watt_L3", Watt_L3);
  532. //entfernt MeldeWert("VA_L1", VA_L1);
  533. //entfernt MeldeWert("Total_KWh", Total_KWh);
  534.  
  535.  
  536.  
  537.  
  538.  
  539. //Update Millis
  540. //entfernt previousMillis = currentMillis;
  541. //entfernt }
  542. }
  543.  
  544. //Send Value to Homematic
  545. //entfernt void MeldeWert(char* WertName, float Value)
  546. //entfernt {
  547. //entfernt String meldung = "";
  548. //entfernt WiFiClient client; // Webclient initialisieren
  549. //entfernt if (!client.connect(host, 8181)) { // mit dem CCU-Port 8181 verbinden
  550. //entfernt //Serial.println(" Fehler: Verbindung zur CCU konnte nicht aufgebaut werden");
  551. //entfernt delay(50);
  552. //entfernt return;
  553. //entfernt }
  554. //entfernt meldung = meldung + "GET /eriwan.exe?befehl=dom.GetObject('" + WertName + "').State('" + Value + "')";
  555. //entfernt client.println(meldung); // Daten an CCU melden
  556. //entfernt}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement