Dear arduino guru's,
For a few months I have been stuck; I have 2nr. individually good working sketches as part of my home power monitoring project.
I would like to run both in one sketch. Not simultaneous, but alternately
Meaning first complete sketch 1, then start sketch 2, after completion sketch 2, start again sketch 1, and so on...
One would think: "make a function of each sketch and call each function at its turn in the void loop."
This yet has not been successful. The compiling is ok, however the output is fragmented.
I have an Arduino Mega + W5100 shield
Sketch 1: registers my energy (smart) meter's serial communication and sends data to online server (working)
Sketch 2: registers output of various current sensors (working)
Output of Sketch 1 (working):
Emoncms client starting...
My IP address: 10.0.0.160
Server IP address: www.emoncms.org
Activate Smart Meter Port P1... 1
-------------------------------------------------------
/ISk5\2MT382-1004
0-0:96.1.1(5A42455630303531373930399343133)
1-0:1.8.1(07960.781*kWh)
1-0:1.8.2(07172.746*kWh)
1-0:2.8.1(00000.003*kWh)
1-0:2.8.2(00000.000*kWh)
0-0:96.14.0(0001)
1-0:1.7.0(0000.45*kW)
LOW RATE (W): 7960781
HIGH RATE (W): 7172746
ACTUAL CONSUMPTION (W): 45
TOTAL CONSUMPTION (kWh): 5447527.00
TOTAL COST (EUR): 1174.22
1-0:2.7.0(0000.00*kW)
0-0:17.0.0(0999.00*kW)
0-0:96.3.10(1)
Output of Sketch 2 (working):
0.68 12.66 0.66 19.28 0.05
0.58 1.48 0.67 2.22 0.39
0.60 1.63 0.67 2.42 0.37
0.43 8.80 0.46 19.34 0.05
0.05 0.94 0.49 1.94 0.05
0.06 1.04 0.49 2.09 0.06
1.36 8.25 0.40 20.54 0.17
-0.16 3.11 0.49 6.41 -0.05
-0.52 2.46 0.58 4.26 -0.21
0.34 8.95 0.47 19.24 0.04
Output of Sketch 1 & 2 combined:
0.35 9.76 0.59 16.41 0.04
0.58 1.33 0.59 2.23 0.44
0.57 1.49 0.61 2.44 0.38
Connecting... Connection failed!
GET /api/post?apikey=f45ae0cd475a645e2dfa5f8c23ec5f6&json=(LowRateConsumption:0,HighRate Consumption:0,ActualConsumption:0,TotalConsumption:0.00,TotalCost:0.00) HTTP:/1.1
Host:emoncms.org
User-Agent: Arduino-ethernet
Connection: close
---------------------------------------------------------
0.11 6.51 0.40 16.37 0.02
0.04 0.83 0.41 2.01 0.04
-0.38 4.40 0.52 8.38 -0.09
Connecting... Connection failed!
GET /api/post?apikey=f45ae0cd475a645e2dfa5f8c23ec5f6&json=(LowRateConsumption:0,HighRate Consumption:0,ActualConsumption:0,TotalConsumption:0.00,TotalCost:0.00) HTTP:/1.1
Host:emoncms.org
User-Agent: Arduino-ethernet
Connection: close
---------------------------------------------------------
etc.
Please find attached Sketch1 & 2 (working).
Please find attached Sketch 3 (combination of 1 & 2 = not working).
(please note that I put for this example a fake API key)
I hope somebody is more skilled than I am and can explain why the output of the above sketch doesn't show anything from the energy smart meter, but only output from the current sensors + fail to connect to server message. (--> I should be able to fix the fail to connect issue)
Any advise or comment that would give me a new angle will be very welcome guys!
Thank you greatly in advance and please let me know if you have any questions.
Kind regards,
Vernon
Sketch1.ino (5.74 KB)
Sketch2.ino (2.66 KB)
Sketch3.ino (7.74 KB)