Esp8266 --multiple flow heat meter for heat pumps and solar thermals

Not sure if any one’s interested – but here’s a copy of my Flow heat Meter. I used a nodemcu and a nodemcu development base. ( $5)
2 flow meters connected to pins D7 and D8 ( $16 DN25)
4 ds18b20 connected to pin D4 ($4)
total $25
the hardest thing is setting up and zeroing out the ds18b20 as there is significant difference in temperature reads between different ds18b20s, and finding ds18b20s that give a constant stable temperature read with very little variation. but i allowed an area for ds calibration…
it takes sampling for and publishes at 5 second intervals. in MQTT Json format -
it will publish to topic FlowA and FlowB
it lists:
input temps (c)
output temps (c)
Flow rate ( l/s)
and energy (w) in both negative and positive values (i.e. if you have a heat pump connected to a radiant floor, it will tell the rate at which the floor is aborbing. when the heat pump is on, it will also tell what rate the floor is losing energy at any given moment – it give’s it in near realtime output, and can be graphed like emontx.- which is useful as you can figure out “realtime” COP and solar thermal energy output to the ~ second - as if they were PV panels – accuracy is reasonable. when error corrected it is about ~0.02- 0.05 degree, which is better than the 0.5c when not error corrected

if using Node-red to process the MQTT packet you will need to pass it through JSON function to convert it from string to an object
in node-red:
MQTT >> JSON>> FREEBOARD

espflowtempjsonW.ino.zip (2.6 KB)

good luck have fun

5 Likes

Hi Stephan,

I tried to use your code with arduinoJson 6 but is doesn’t work. I made a change “StaticJsonBuffer<200> jsonBuffer;” to “StaticJsonDocument<200> doc;” I don’t see any other Json programming in your Is it a lot of work to change your code for ArduinoJson 5 to ArduinoJson 6. I think I will help a lot of people, who wants to monitor there heatpump.
thank a lot
greetz Peter

what sort of error do you get when to run it . as i think I started out going to to use arduinojson.h but then just manual constructed the json instead so it does not even rely on it you should be able to comment out those lines arduinojson.h and StaticJsonBuffer<200> jsonBuffer;

if I remember correctly

Hi, Stephen,
I now can compile you sketch, I downgraded the Json library to version 5 and left your version original. I compiled and uploaded it to an Wemos D1 board. But in the serial screen I see that the board is not resonding as I should, see screenshot. Any idea what I’m doing wrong?

Hi Stephan,

Forgot to say that I comment out the lines arduinojson.h and StaticJsonBuffer<200> jsonBuffer;
Is there a difference in programming in NodeMCU and the Wemos D1 I’am using?

first off does the wemos work with other basic ino ?
since stuff changes all the time what I would do is comment each void block leaving only the void setup() ( commenting out the last three lines setup_wifi(); … etc that call other voids and functions )and work my way through to see what breaking it. i suspect it either something in dallastemperature or how it connect to the network and functions have changed so they need to be updated
example :

/*
void flow2()
{
flow2count +=1;
flowbcount +=1;
}
*/

see if it starts and runs that block… if it crashes there maybe something changed in DallasTemperature.h see what changed there…
nexted move on to setup_wifi ()

does it start and connect if not see what changed there

and work yourself through each block to find what got broken with library updates

Thanks, I will try that, I let you know if it works,

thanks a loot for your effort

kind regards, Peter

oh yeah and I just remembered a weird quirk of arduino IDE that was introduced later on and wemos sometimes there nothing wrong with the code itself it just being particular on the order at which it calls it … when there a function call the function has to be before the void that called it …

so in the case of this ino you might just have to move void setup_wifi() before void setup() – as this is the only one that I see doing that

That’s a bit confusing - I think you have the names mixed up.

void flow2();
is a function declaration. (It is defined somewhere else.)

void flow2()
{
flow2count +=1;
flowbcount +=1;
}

is a function definition.

flow2();
is a function call.

Hi Stephan,
I tried your suggestion to move the wifi program blok, but that doesn’t work either.
I orderd some nodeMCU boards at ali-express that takes a while, I hope that the program will work with nodeMCU. I will let you know in this forum,

Kind regards, Peter

Hi Stephen,
I have the nodeMCU board, but had still the same problem.
after some experimenting, I commented out pinmode(flowPin1, INPUT)
and AttachInterurrupt, see the attachment. and void flow1 and void flow 2
after that I got a good result on my serial monitor. So the board did not reset anymore.
multiple flow heat meter ino.pdf (94.3 KB)

Any idea what is going wrong?

maybe the AttachInterurrupt format changed since I wrote this

try writing a small sketch that just looks at your flow meter

here a sample sketches
esp_mqtt_flow.ino (2.5 KB)

FlowMeterDIY.ino (3.8 KB)

flow.ino (6.3 KB)

but from looking around the web a little bit it seams they changed the usage of unsigned long to volatile long for the esp – I have not tested just a little look around to see what might of change since

many thanks, I will try this, I let you know

You need to declare a variable that is shared between the Interrupt Service Routine and the main program as “volatile” in order to prevent the compiler from optimising the code - which might lead to the code not working as you intend. Declaring a variable as volatile doesn’t change the type of variable - you can have a volatile unsigned long or a volatile (signed) long.

hi there - I tried loading the original sketch on to an empty wemos mini it worked fine with no errors

Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Publish message: { "devices": "A","payload": {"Input": -127.00,"Output": -126.85,"Flow": 0.00,"Watt": 0.00}}
Publish message: { "devices": "B","payload": {"Input": -127.00,"Output": -127.00,"Flow": 0.00,"Watt": 0.00}}
Flow 1 in Liters: 0.00	Flow 2 in Liters: 0.00	Flow 1 in pulses: 0	Flow 2 in pulse: 0
Requesting temperatures...DONE

I think maybe your problem might be just D7 D8 – you might just have to change that to GPIO D8 = 0 D7 = 13

background software versions I am using arduino ide 1.8.10 esp8266 2.3.0

My main computer has a kernel bug that does not work with esp at the moment or intermittently I had to switch HD to boot in older system

Ok great Stephen, I will try it tomorrow, I let you know if it works,
thanks for all your work, and help

Greetz, Peter

just for your info - I did an update and my kernel was patched today so now I can flash esp again – I tried the newest esp8266 and it crashes as you say- reverted back to 2.3.0 and it flashed fine . tried 2.6.0 crashes again from the looks they changed something in the attachedinterrupt as all I need to do is comment out those two lines and it no longer crashes… so either revert back to 2.3.0 and flash or figure out what they changed in the newer versions

for what I use I like Version 2.3.0 from what I see the much newer ones compile so slowly and upload even slower

Yessss, it works, I had the also the latest version of the 8266 and that gave the error. I downgraded the version to 2.3.0 and now it works like a charm,

Thanks very much,

Greetz Peter

Connecting to Linksys

WiFi connected
IP address:
192.168.1.158
Flow 1 in Liters: 0.00 Flow 2 in Liters: 0.00 Flow 1 in pulses: 0 Flow 2 in pulse: 0
Requesting temperatures…DONE
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Attempting MQTT connection…connected
Flow 1 in Liters: 0.00 Flow 2 in Liters: 0.00 Flow 1 in pulses: 0 Flow 2 in pulse: 0
Requesting temperatures…DONE
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Publish message: { “devices”: “A”,“payload”: {“Input”: -127.00,“Output”: -126.85,“Flow”: 0.00,“Watt”: 0.00}}
Publish message: { “devices”: “B”,“payload”: {“Input”: -127.00,“Output”: -127.00,“Flow”: 0.00,“Watt”: 0.00}}
Flow 1 in Liters: 0.00 Flow 2 in Liters: 0.00 Flow 1 in pulses: 0 Flow 2 in pulse: 0
Requesting temperatures…DONE
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Flow 1 in Liters: 0.00 Flow 2 in Liters: 0.00 Flow 1 in pulses: 0 Flo

1 Like

Just one thing Stephan,
I connected 4 temperature sensors, but the program doesn’t find the first (device 0)
sensor. I checked the program but could not find any problem.
do you know what could be the problem?
thanks,

Connecting to Linksys

WiFi connected
IP address:
192.168.1.144
Flow 1 in Liters: 0.00 Flow 2 in Liters: 0.00 Flow 1 in pulses: 0 Flow 2 in pulse: 0
Requesting temperatures…DONE
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 28FFABAE6216047A Temp C: 23.00 Temp F: 73.40
Device Address: 28FF0FAF621604D9 Temp C: 22.75 Temp F: 72.95
Device Address: 28FF7FC4541604BF Temp C: 22.87 Temp F: 73.18
Attempting MQTT connection…connected
Flow 1 in Liters: 0.00 Flow 2 in Liters: 0.00 Flow 1 in pulses: 0 Flow 2 in pulse: 0
Requesting temperatures…DONE
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 28FFABAE6216047A Temp C: 23.00 Temp F: 73.40
Device Address: 28FF0FAF621604D9 Temp C: 22.75 Temp F: 72.95
Device Address: 28FF7FC4541604BF Temp C: 22.94 Temp F: 73.29
Publish message: { “devices”: “A”,“payload”: {“Input”: -127.00,“Output”: 23.15,“Flow”: 0.00,“Watt”: 0.00}}
Publish message: { “devices”: “B”,“payload”: {“Input”: 22.75,“Output”: 22.94,“Flow”: 0.00,“Watt”: -0.00}}
Flow 1 in Liters: 0.00 Flow 2 in Liters: 0.00 Flow 1 in pulses: 0 Flow 2 in pulse: 0
Requesting temperatures…DONE
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 28FFABAE6216047A Temp C: 23.00 Temp F: 73.40
Device Address: 28FF0FAF621604D9 Temp C: 22.75 Temp F: 72.95
Device Address: 28FF7FC4541604BF Temp C: 22.87 Temp F: 73.18
Flow 1 in Liters: 0.00 Flow 2 in Liters: 0.00 Flow 1 in pulses: 0 Flow 2 in pulse: 0
Requesting temperatures…DONE
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 28FFABAE6216047A Temp C: 23.00 Temp F: 73.40

either sensor connected incorrectly or bad sensor I would suspect