Modbus – Boiler – Triangle Tube Prestige Trimax Solo
Bron: sandeen.net
Info (ENG)
We recently upgraded our boiler to a high-efficiency modulating/condensing Triangle Tube Prestige Trimax Solo, and in perusing the manual, I found that the boiler has a ModBus interface . Woohoo, project! The final result is live charting like you see above; for more details, read on!
Per the boiler docs, the ModBus interface is Modbus/RTU using RS-485 for the physical layer. First thing, obviously, is to find an RS-485 adapter.
The adapter only has A and B connections, and no GND, but it works fine. I used a twisted pair from a CAT5 cable to connect to the A and B terminals on the boiler, plugged it into a spare Raspberry Pi, and was ready to test this thing.
libmodbus makes communication simple; basically open the serial port and read addresses. A little test program I wrote verified that things are working:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
/* * Copyright (c) 2014 Eric Sandeen <sandeen@sandeen.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * tt-status: Show status of a Triangle Tube Solo Prestige boiler via ModBus * * Usually pointed at a RS-485 serial port device, but may also query through * a ModBus/TCP gateway such as mbusd (http://http://mbus.sourceforge.net/) */ #include <errno.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <time.h> #include <modbus/modbus.h> #define CHECK_BIT(var,pos) ((var) & (1<<(pos))) void usage(void) { printf("Usage: tt-status [-h] [-d] [-S slave] [-c|-t] -s serial port][-i ip addr [-p port]]\n\n"); printf("-h\tShow this help\n"); printf("-d\tEnable debug, default 0\n"); printf("-S\tModbus slave id, default 1\n"); printf("-c\tExport in CSV\n"); printf("-t\tExport in thingspeak\n"); printf("-s\tSerial Port Device for ModBus/RTU\n"); printf("-i\tIP Address for ModBus/TCP\n"); printf("-p\tTCP Port for ModBus/TCP (optional, default 502)\n"); exit(1); } float c_to_f(float c) { return ((c * 9)/5 + 32); } struct status_bits { int bit; char *desc; }; struct status_bits status[] = { { 0, "PC Manual Mode" }, { 1, "DHW Mode" }, { 2, "CH Mode" }, { 3, "Freeze Protection Mode" }, { 4, "Flame Present" }, { 5, "CH(1) Pump" }, { 6, "DHW Pump" }, { 7, "System / CH2 Pump" } }; uint16_t status_regs[1];/* Holds results of register reads */ uint16_t temp_regs[9]; /* Holds results of register reads */ uint16_t setpt_regs[2]; /* Holds results of register reads */ void csv_print(void) { int i; printf("%d", time(NULL)); printf(",%d", status_regs[0]); for (i = 0; i < 9; i++) printf(",%d", temp_regs[i]); for (i = 0; i < 2; i++) printf(",%d", setpt_regs[i]); printf("\n"); } void thingspeak_print(void) { /* Setpoint */ if (temp_regs[8] != 0x8000) printf("field1=%.1f&", c_to_f(temp_regs[8])); else printf("field1=%d&", 0); /* firing rate */ printf("field2=%d&", temp_regs[7]); /* supply temp */ printf("field3=%.1f&", c_to_f(temp_regs[0]/10)); /* return temp */ printf("field4=%.1f&", c_to_f(temp_regs[1])); /* outdoor temp */ printf("field5=%.1f&", c_to_f((int16_t)temp_regs[4])); /* DHW temp */ printf("field6=%.1f&", c_to_f((int16_t)temp_regs[2])); /* Status */ printf("field7=%d\n", status_regs[0]); } void pretty_print(void) { int i; printf("Status:\n"); if (status_regs[0] == 0) printf(" Standby\n"); for (i = 0; i < 7; i++) { if (CHECK_BIT(status_regs[0], i)) printf(" %s\n", status[i].desc); } /* Supply temp: 0.1 degree C, 16 bits */ printf("Supply temp:\t\t%3.0f °F\n", c_to_f(temp_regs[0]/10)); /* Return temp: degrees C, 8 bits */ printf("Return temp:\t\t%3.0f °F\n", c_to_f(temp_regs[1])); /* DHW storage temp */ printf("DHW Storage temp:\t%3.0f °F\n", c_to_f(temp_regs[2])); /* Flue temp: degrees C, 8 bits */ printf("Flue temp:\t\t%3.0f °F\n", c_to_f(temp_regs[3])); /* Outdoor temp: degrees C, 8 bits */ printf("Outdoor temp:\t\t%3.0f °F\n", c_to_f((int16_t)temp_regs[4])); /* Future use, 5 */ /* Flame Ionization: μA, 8 bits */ printf("Flame Ionization:\t%3d μA\n", temp_regs[6]); /* Firing rate: % 8 bits */ printf("Firing rate:\t\t%3d %\n", temp_regs[7]); /* Boiler setpoint: degrees C, 8 bits, only if firing */ if (temp_regs[8] != 0x8000) printf("Boiler Setpoint:\t\t%3.0f °F\n", c_to_f(temp_regs[8])); /* CH1 Maximum Setpoint C, 8 bits */ printf("CH1 Maximum Setpoint:\t%3.0f °F\n", c_to_f(setpt_regs[0])); /* DHW setpoint: degrees C, 8 bits, only if set */ if (setpt_regs[1] != 0x8000) printf("DHW Setpoint:\t\t%3.0f °F\n", c_to_f(setpt_regs[1])); } typedef enum { PRETTY, CSV, THINGSPEAK } printtype; int modbus_read_boiler(modbus_t *mb) { /* Read 1 register from the address 0 for status bitfield */ if (modbus_read_input_registers(mb, 0, 1, status_regs) != 1) { printf("Error: Modbus read of 1 byte at addr 0 failed\n"); return 1; } /* Read 9 registers from the address 0x300 */ if (modbus_read_input_registers(mb, 0x300, 9, temp_regs) != 9) { printf("Error: Modbus read of 9 bytes at addr 0x300 failed\n"); return 1; } /* Read 2 registers from the address 0x500 */ if (modbus_read_registers(mb, 0x500, 2, setpt_regs) != 2) { printf("Error: Modbus read of 2 bytes at addr 0x500 failed\n"); return 1; } return 0; } int main(int argc, char **argv) { int c; int err = 1; int slave = 1; /* default modbus slave ID */ int debug = 0; /* enable debug */ int port = 502; /* default ModBus/TCP port */ char ipaddr[16] = ""; /* ModBus/TCP ip address */ char serport[32] = ""; /* ModBus/RTU serial port */ modbus_t *mb; /* ModBus context */ uint16_t regs[8]; /* Holds results of register reads */ printtype output = PRETTY; while ((c = getopt(argc, argv, "cdths:i:p:S")) != -1) { switch (c) { case 'c': output = CSV; break; case 't': output = THINGSPEAK; break; case 'h': usage(); break; case 'd': debug++; break; case 's': strncpy(serport, optarg, sizeof(serport)); serport[31] = '\0'; break; case 'i': strncpy(ipaddr, optarg, sizeof(ipaddr)); ipaddr[15] = '\0'; break; case 'p': port = atoi(optarg); break; case 'S': slave = atoi(optarg); break; default: usage(); } } if (!ipaddr[0] && !serport[0]) { printf("Error: Must specify either ip addresss or serial port\n\n"); usage(); } if (ipaddr[0] && serport[0]) { printf("Error: Must specify only one of ip addresss or serial port\n\n"); usage(); } if (ipaddr[0]) mb = modbus_new_tcp(ipaddr, port); else mb = modbus_new_rtu(serport, 38400, 'N', 8, 1); if (!mb) { perror("Error: modbus_new failed"); goto out; } if (debug) modbus_set_debug(mb,TRUE); if (modbus_set_slave(mb, slave)) { perror("Error: modbus_set_slave failed"); goto out; } if (modbus_connect(mb)) { perror("Error: modbus_connect failed"); goto out; } if ((err = modbus_read_boiler(mb))) goto out; if (output == PRETTY) pretty_print(); else if (output == CSV) csv_print(); else if (output == THINGSPEAK) thingspeak_print(); err = 0; out: modbus_close(mb); modbus_free(mb); return err; } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# ./tt-status -s /dev/ttyUSB0 Status: DHW Mode Flame Present DHW Pump Supply temp: 168 °F Return temp: 145 °F DHW Storage temp: 102 °F Flue temp: 132 °F Outdoor temp: 35 °F Flame Ionization: 11 ?A Firing rate: 25 % Boiler Setpoint: 170 °F CH1 Maximum Setpoint: 143 °F DHW Setpoint: 125 °F |
Ok! So to get the pretty graph above, I obviously needed some data collection; for this I used collectd simply because it already had a ModBus plugin. It did require some patching and hacking though; the non-bloggy details are on this page; the graph you see above was made by Visage.
Overall this has been very useful; the boiler controls are fairly involved, but primarily we want to get the outdoor reset curve tweaked so that we get nice long runtimes and low return temps, which keep the boiler in its most efficient condensing mode. My installer hit the default buttons and left, as contractors often do. Seeing how the boiler was working over time definitely helped me tweak things to improve performance, efficiency and comfort. Primarily, I drastically lowered the high end of the outdoor reset curve which defaulted to 170F For cast iron radiators, because we have much more radiation in this house than it needs at 170F output. I currently have the high end set to 140F. I may do another post on all that later… suffice it to say, doing a heat loss and measuring radiation and using that information to guide boiler setup is not rocket science, and you really need to do it for the sake of comfort and efficiency.
collectd, at least with the rrd output, doesn’t keep fine-grained data around for long. The current setup is useful for seeing how things behaved in the past couple days, but I’ll probably start logging fine-grained data to a database at some point, and can start doing fun things like using the firing rate to estimate gas usage over the month, look at therms per heating degree days in near real time, etc.
Other boilers have ModBus interfaces as well; in particular Lochinvar and NTI both mention the capability, although I haven’t yet found documentation on what data is available. If you have a boiler with ModBus and want to try this hack, drop me a line – I’d love to see how this looks in other homes, and I’d be glad to help you set up a collectd config file. I may see about creating a Raspberry Pi image to make this all more or less work out of the box.
Again, take a look at the the more detailed writeup for a bit more info, in particular the patches I used with the upstream tools, and if you try this at home & make it work, share what you find!