EcoRenovator

EcoRenovator (https://ecorenovator.org/forum/index.php)
-   Geothermal & Heat Pumps (https://ecorenovator.org/forum/forumdisplay.php?f=10)
-   -   IOT heatpump controller (https://ecorenovator.org/forum/showthread.php?t=5017)

Acuario 01-16-17 09:20 AM

IOT heatpump controller
 
5 Attachment(s)
Sadly my old Roca heat pump compressor died.

Fortunately my local scrap man turned up for a pickup and had a mid-size Daiichi external unit in the back of his van. I persuaded him to part with it on the off chance it worked, and as luck would have it it did, and it appeared to have been gassed down so still contained a charge, result!

http://ecorenovator.org/forum/attach...1&d=1484579186

So it was time for a new controller :D

I have come to several conclusions having built various controllers both for solar hot water and for heat pumps over the last few years:
  1. DS18B20 temperature sensors are a pain. Better and easier to use 10K NTC thermistors.
  2. PIC processors are fun but limited and libraries are few and often don't work. Ethernet or any networking is a big challenge.
  3. Arduino UNO and NANO are cheap and cheerful but have limited memory so adding a web server with various pages isn't really possible.
  4. Arduino Mega is better but becomes bulky with peripherals. Web pages are possible but need to be either on an sd card or coded into an output stream. It also struggles with performance serving web pages.

So, not too long ago a wizzy little chip appeared on the market and took the world by storm - the ESP8266.

This chip comes in various module flavours with different flash memory sizes and pin outs. For experimenting you can't go far wrong with the NodeMCU board as it comes with everything on the pcb, just plug it in to a USB port and you're ready to go. It even has an on board interpreter, LUA, however I'm not a fan so don't use that.

The great thing about the esp is that it has all the Arduino code available so you can use it as if it were an Arduino, even using the Arduino IDE (although I personally use Visual Studio with the Visual Micro add-on).

Most Arduino libraries work out of the box, others have been ported to the esp so it really is a dream.

It has built in WiFi, loads of memory, Works well as a web server and can be upgraded over the air (ota), which means you can send your updated code to it from anywhere, no need to plug in cables or even physically touch the device.

So, this was my choice for the new controller.

I recently designed a pcb for a generator auto start system that can take either an Arduino NANO or an ESP12 so I used one of them for the main controller.

http://ecorenovator.org/forum/attach...1&d=1484578530

The esp is mostly hidden as it needs 3.3V so I use a DC/DC converter from 5V which sits above the esp.

The control board is sparsely populated, in reality there are only 6 resistors and a few connectors used.

The esp only has one adc pin, this I use with a 10K thermistor for reading the actual temperature the water has reached . These you can buy for very little money with a waterproof case and connector lead from ebay.

http://ecorenovator.org/forum/attach...1&d=1484578530

As I have moved to thermistors for Reading temperatures I obviously need more analogue inputs. For the extra inputs I'm using a PCF8591 I2C module (from ebay) with 4 x sensors. Also for controlling the relays another I2C device, a PCF8574A expander, (ebay again). I wanted the control box inside and the relays/sensors out so running a 4 core cable and using I2C to talk to the peripherals works perfectly.

So, the esp is happy to serve up web pages so rather than as I have done in the past, add a display and keypad, as we are going IOT it should all be done via web pages, two to be precise, one to show status information and the other to perform setup operations, much prettier than an LCD display and much easier to use!

This is the status page showing current operating parameters:
http://ecorenovator.org/forum/attach...1&d=1484850501

And this is the setup page:
http://ecorenovator.org/forum/attach...1&d=1484850501

Being connected into my local network I can open up the port the controller is using, set up port forwarding on my internal router and can then access my controller from anywhere I can connect to the internet. And yes, it does have login security!

Acuario

AC_Hacker 01-19-17 11:30 AM

Acuario Rules!!

AC_Hacker 01-19-17 11:33 AM

One more thing...

Were you ever able to achieve success in controlling a variable-frequency mini-split??

-AC

Acuario 01-19-17 12:10 PM

1 Attachment(s)
That's a Project I have pending and made much easier now I've mastered the esp and real time os. The machine is still in my shed connected up and waiting.

The problem to date (apart from time...) has been finding a device powerful enough and flexible enough to use for the project, this I think is now solved with the esp. I didn't really fancy trying it with a pi or c.h.i.p. although if the esp gives me problems I may try one of them.

By the way, aside from the heat pump controller I have "IOT'd" the controllers for both the solar hot water and solar central heating. With the hot water controller I added statistics for interest and have been surprised that even now in early January I've had just over 25 hours of running time in the last week.

http://ecorenovator.org/forum/attach...1&d=1484849563

pedro 01-20-17 08:02 PM

Can you describe a little more how you would control a pump? I looked up the expansion module. Do you just use that to control a relay that sends power to the pump?

Acuario 01-20-17 11:25 PM

The expansion module just gives me more outputs without the need to either use up GPIO ports on the esp or run extra cables. As it works on the I2C bus it uses the same 4 control wires as the ADC converter.

The outputs from the expander run 3 relays, 2 are on one of the little 2 relay boards that have all the driver circuit built onto the board. These run the fan and 3 way valve. The other is a solid state relay (SSR) for the compressor.

This is an old unit that has a capillary tube so there is no need to control an eev.

Ron342 01-24-17 10:03 AM

Wow!
 
Well, i had been sitting here looking at this $6 ESP8266 i ordered and wondered if i would live long enough to be able to learn to get it to report temps over wifi to the web and controll my geo h/w heater build - and you've already finished it - great work guy!
There is also a esp based bpard for about $10 that has expansions with relays to report temp and humidity logging and control of pumps etc thru the relays but they are i think relays that need to be constantly powered on ie not tripped.
Google "Sonoff" they are all over the web.
I wonder how this stacks up against Xringers X10RF web control??
If you get a chance, when you finish, a detailed (read handholding) description of how you hooked it up and programmed it would be a huge boost to those of us who didn't grow up with this stuff!
Thanks!

Acuario 01-25-17 05:08 AM

I've seen the sonoff devices, good devices and can be re-programmed so could be used as a pre-built controller with a few additions.

The sonoff SC is the unit that has the humidity/temperature sensors but they have opted to use the atmega328P (read Arduino) for adc to overcome the esp limitation.

There's a detailed look with modifications here:
Sonoff SC with MQTT and Domoticz support - Tinkerman

Also a guy called Peter Scargill has done lots with them
IOT Technology Blog

I'll post more details in a subsequent post.

Acuario

Acuario 01-25-17 09:30 AM

Putting it all together - how it works
 
4 Attachment(s)
If you haven't read my posting on the dew point monitor it would be advisable before reading this as it may make more sense...

Part 1 - the hardware

The schematics for all 3 parts of the project are incredibly simple.
There are 3 parts, 2 for the controller and the separate dew point monitor.

1. Main controller

http://ecorenovator.org/forum/attach...1&d=1485355416

This comprises of little more than a (not shown) 5VDC power supply, 5V to 3V3 power supply (not shown either), an ESP-12 and the resistors needed to make it work and a 10K thermistor connected to the adc input. The I2C bus (2 wires + 5V power) is fed out to the peripherals that are located inside the external unit. The RS232 connection is really only used to program the controller the first time (or if something really screws up!) as any code updates can be done remotely ota (over the air).

2. Peripherals

http://ecorenovator.org/forum/attach...1&d=1485355482

The peripherals comprise 3 x pre-built modules, one to read the temperatures using thermistors and the other a port expander to switch the relays (2 on a pre-built board) on and off. The main relay for the compressor is a 40A solid state relay.

3. Dew point, temperature and humidity monitor

http://ecorenovator.org/forum/attach...1&d=1485355482

Again ridiculously simple, an ESP-01 connected to a DHT-22 humidity/temperature sensor, a status LED and a button for WPS. Not shown is the 5VDC power supply.

Part 2 - the software

The whole system runs on the Arduino ESP8266 software API and is written in C for the main code and HTML for the web pages.

All the libraries used in the project are open source.

The libraries are:
  • Timezone - this allows the clock, which is synchronised from an NTP time server, to display my local time
  • ArduinoOTA - This enables ota updates
  • ESPAsyncWebServer - this is a much more responsive web server than comes with the standard Arduino ESP implementation
  • Ticker - This allows for co-operative multi tasking, i.e. deciding how often a particular code module will be run. There is little point reading tempertures every second, every 30 is more than sufficient whereas updating the clock every second gives a better visual display. This allows control of this.
  • Wire - This is for the communication over I2C from the controller to the peripherals.
  • EEPROM - Allows reading/writing to the ESP eeprom to store/retrieve operating parameters.
  • WiFiUdp - This is used for the UDP clients to communicate with both the NTP time server and the Dew point monitor.

The project also uses the ESP SPI file system (SPIFFS) for storing web pages and stuff required by the web pages.

The code is broken down into modules with discreet functions:
  • Read system settings - done once at start up
  • Read sensors - every 30 seconds
  • Check defrost step and manage defrost cycle (if defrost is running) - every second
  • Read dew point sensor - every 60 seconds
  • Read and/or refresh time from time server - every second to update time, every hour to synchronise
  • Logic to check if a defrost is needed - checks evaporator temperature and if < set defrost point for > defrost delay time, run a defrost cycle
  • Set relay states - turns relays on and off as needed

A web server is also running in the background to handle any user input. Updates are sent to the web browser using a protocol called server-sent events. This protocol is handled on Chrome (and others) but not Internet Explorer or Microsoft Edge. The alternative would have been to use AJAX but that would have needed to be initiated from the browser so immediate updates wouldn't have happened. Another possibility that I tried out was web sockets but I kept getting timeouts so ended up abandoning them.

Acuario

jeff5may 01-18-21 03:45 PM

Ok so I decided to post in this thread as not to pollute the other, newer version thread.

I've recently been tinkering with more phase change monsters and have decided to have another go at the custom built interface. Nobody seemed to like the Arduino uno or nano modules, due to the limited functionality. Since these esp boards are super affordable, they look acceptable to me. The two main choices for the project look to be the esp8266 and the esp32 modules. I like the esp32 better, due to the more robust gpio and onboard flash memory. Double the price, but we're talking about 10 versus 20 dollars here. I believe the extra gimmicks are sufficient to satisfy the desires of a lot more tinkerers.

I could get by with the 8266 and a few extra expansions, but with the 32, it would only need "muscle" controls, with many options available for sensing and communication built-in. The 3.3 volt logic levels are no big deal, since there are so many compatible expansion modules available.

So here's the part where I respectfully beg for information. I'll take whatever you have to share. Since what you're using obviously works, I'd love to pilfer through source code and see how it ticks. I promise I won't break it and post up a bunch of stuff that doesn't work well.

With the uno, the code had to be small and simple to conserve resources. Not a lot of people could follow the kiss method or understand some things I did to keep it small. Communication with the outside world was a point of contention as well. Flashy lights vs 7 segment vs what have you, everyone had different desires. With WiFi and i2c interfaces onboard, as well as a gaggle of spare output pins available, someone could plausibly go their own way and not have to redo the core functionality.

Acuario 01-19-21 01:15 AM

2 Attachment(s)
Sounds interesting...
The ESP32 is a good option if starting from nothing as you say, more GPIO and ADC possibilities. There is also onboard bluetooth and it is also possible to connect an ethernet interface. I think the memory is the same though as an ESP12 (which is what I use), 4Mb, although this should be more than enough. It didn't exist when I started my controller, that's why I used the ESP8266.

I added my own design expansion board (controlled with I2C) with a 4 channel ADC and 8 channel I/O to overcome the limitations of the ESP8266 - as I designed my own pcb I also incorporated all the driver circuitry, connectors and relays onto the board. You could certainly build a controller without a custom pcb, just connecting to expansion modules directly with wires.

As stated above, I tried with DS18B20 sensors but in the end went back to 10K NTC sensors.

I control the pump, fan and reversing valve with mechanical relays and the compressor with a SSR, the SSR should work with a 3.3V control but as I have my I/O I'm using a 5V input.

Originally I had a physical interface (buttons and OLED display) for programming but I abandoned that and went 100% web based as it's much more flexible and easier to program.

As an IDE I (still) use the Visual Micro extension to Visual Studio - does pretty much everything I need.

I think most of the libraries I'm using support ESP32 so it shouldn't be too difficult to move to ESP32.

I've attached my code - it's somewhat documented so hopefully understandable. There are a few bits of legacy code and some bits I use when testing out possible new features but that shouldn't cause any problems.

It looks like cloudMQTT no longer have free MQTT accounts so you'll need to look elsewhere and update the MQTT details.

openweather shouldn't be a problem.

Maybe it's worth buying a WemosD1 and loading the code onto that, from there you can move to the ESP32. It should all run quite happily on the WeMos, even without sensors or relays connected. You can check out the web interface etc...


You need to add a file Passwords.h with the following:
Quote:

#pragma once

//Arduino OTA password
constexpr auto OTA_PASSWORD = "<your ota password>";

//MQTT (cloudMQTT.com)
constexpr auto MQTT_USER = "<your username>";
constexpr auto MQTT_PASS = "<your password>";
constexpr auto MQTT_HOST = "m20.cloudmqtt.com";
constexpr auto MQTT_PORT = 19167;

//Wifi networks - add more in WiFiWPS.cpp for more networks
constexpr auto SSID_1 = "<your ssid>";
constexpr auto PASS_1 = "<your pass>";
constexpr auto SSID_2 = "<your ssid>";
constexpr auto PASS_2 = "<your pass>";

//Weather (openweathermap.org)
constexpr auto CURRENT_WEATHER = "/data/2.5/weather?id=3107677&units=metric&APPID=<your id>";
constexpr auto FORECAST_3HR = "/data/2.5/forecast?id=3107677&cnt=3&units=metric&APPID=<your id>";
And a file board.txt
Quote:

# HPControllerESP build property overrides
#
network.password=<your ota password>
network.auth_upload=yes
network.port=8266

# Force LittleFS Usage for ESP8266
runtime.tools.mkspiffs.path=notTheToolYoureLooking For
Have fun! Let me know if you need any help.

jeff5may 01-19-21 10:36 AM

Tyvm! I've been looking at the original version for awhile now, I think I have a good grip on the overall operation. Haven't dug deep inside subroutines to see exactly where the rubber hits the road, but it works, so for the moment I shouldn't need to.

So you used a wemos d1 module? Mini, pro, or something else version? No indicators at the MCU board at all, totally relying on the WiFi for comms? I like to at least flash the onboard LED (if equipped) with a heartbeat or blink code, just for live status dead reckoning. When shtf, a quick look see to verify status can save all manner of wonder why. Kind of like a furnace control.

Acuario 01-19-21 11:45 AM

I actually have my own designed board that I use - it is actually a slightly hacked board that I use for my thermostats but it has everything I need. It has the ESP-12 soldered onto the pcb - I just suggested the WeMos as a quick hack as I use this as it can be re-programmed via the com port as it uses the RTS to reset - my board doesn't - sometimes the mods throw a wobbly so it's just easier to use the WeMos.

I get the idea about the led - problem sometimes with the ESP8266 is it uses one of the gpio lines and it can be different on different boards.

You'll see there is a watchdog in the code that resets (or should) if something goes wrong. So far I've not had any lockups that I'm aware of - the occasional reset (no idea why) but it always recovers.

Acuario 01-19-21 12:11 PM

A few pointers..
If you get the code up and running then:
If you open Windows Explorer and go to Network you should see your heatpump listed there, double click to open the web interface..

If you open the web interface and go to <your IP>/debug.html you'll see the debug output from all the routines.

With no sensors connected the sensors return -6c, this will force a defrost cycle to occur at regular intervals..

jeff5may 01-19-21 10:44 PM

I had to go google for a minute to figure out what a esp12 was. Doh, it's the same 8266, stripped down. Does it even have a status LED? For 3 bucks shipped to my house, anything more than an unpopulated pcb is a bonus!

https://www.ebay.com/itm/NodeMCU-Lua...4-80ad70937bf3

Oh wait, that's considered a dev board. It has a micro usb port, a reset button and other accessories!


All times are GMT -5. The time now is 03:27 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Ad Management by RedTyger