Subversion Repositories heating

Rev

Rev 53 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 53 Rev 54
Line 209... Line 209...
209
		}
209
		}
210
 
210
 
211
		while (akt)
211
		while (akt)
212
		{
212
		{
213
			/// Set the mode for every room.
213
			/// Set the mode for every room.
214
			if (!onoff)
214
			if (onoff)
215
			{
215
			{
216
				if (loctime >= akt->start && loctime <= akt->end)
216
				if (loctime >= akt->start && loctime <= akt->end)
217
					akt->status = NORMAL;
217
					akt->status = NORMAL;
218
				else
218
				else
219
					akt->status = NIGHT;
219
					akt->status = NIGHT;
Line 222... Line 222...
222
				akt->status = OFF;
222
				akt->status = OFF;
223
 
223
 
224
			tmp = getTemp(akt->tempsensor);
224
			tmp = getTemp(akt->tempsensor);
225
 
225
 
226
			if (tmp < 99.0 && tmp > -99.0)
226
			if (tmp < 99.0 && tmp > -99.0)
-
 
227
			{
227
				akt->ist = tmp;
228
				akt->ist = tmp;
228
 
229
 
229
			if (evaluateTemp(akt->rnum, tmp))			// Should we start heating?
230
				if (evaluateTemp(akt->rnum, tmp))		// Should we start heating?
230
				startHeat(akt->rnum);					// yes
231
					startHeat(akt->rnum);				// yes
231
			else										// Or should we stop heating
232
				else									// Or should we stop heating
232
				stopHeat(akt->rnum);					// yes
233
					stopHeat(akt->rnum);				// yes
-
 
234
			}
233
 
235
 
234
			akt = akt->next;
236
			akt = akt->next;
235
		}
237
		}
236
 
238
 
237
		i++;
239
		i++;
Line 265... Line 267...
265
			break;
267
			break;
266
 
268
 
267
		akt = akt->next;
269
		akt = akt->next;
268
	}
270
	}
269
 
271
 
270
	if (!akt || akt->valve)
272
	if (!akt)
-
 
273
	{
-
 
274
		syslog(LOG_WARNING, "controlHeat: Room %d not found!", room);
271
		return;
275
		return;
-
 
276
	}
-
 
277
 
-
 
278
	if (akt->valve != stst)
-
 
279
	{
-
 
280
		if (Configure.debug)
-
 
281
			syslog(LOG_DEBUG, "Heating for room %d switched %s", room, (stst) ? "ON" : "OFF");
-
 
282
 
-
 
283
		string h = "HEATING:";
-
 
284
		h.append(itostring(room) + ":");
-
 
285
		h.append((stst)? "ON;" : "OFF;");
-
 
286
		answer(h);
-
 
287
	}
272
 
288
 
273
	switch (akt->gpio)
289
	switch (akt->gpio)
274
	{
290
	{
275
		case 1: pin = PIN1; break;
291
		case 1: pin = PIN1; break;
276
		case 2: pin = PIN2; break;
292
		case 2: pin = PIN2; break;
Line 283... Line 299...
283
		case 9: pin = PIN9; break;
299
		case 9: pin = PIN9; break;
284
		default:
300
		default:
285
			return;
301
			return;
286
	}
302
	}
287
 
303
 
-
 
304
	akt->valve = stst;
288
	// Enable the GPIO pin to start heating
305
	// Enable the GPIO pin to start heating
289
	if (!bcm2835_init())
306
	if (!bcmInitialized)
290
		return;
307
		return;
291
 
308
 
292
	// Set the pin to be an output
309
	// Set the pin to be an output
293
	bcm2835_gpio_fsel(pin, BCM2835_GPIO_FSEL_OUTP);
310
	bcm2835_gpio_fsel(pin, BCM2835_GPIO_FSEL_OUTP);
294
	// Turn it on
311
	// Turn it on
295
	bcm2835_gpio_write(pin, (stst)? HIGH : LOW);
312
	bcm2835_gpio_write(pin, (stst)? HIGH : LOW);
296
	akt->valve = stst;
-
 
297
	bcm2835_close();
-
 
298
}
313
}
299
 
314
 
300
double heating::incSoll(int room)
315
double heating::incSoll(int room)
301
{
316
{
302
HCONF *akt;
317
HCONF *akt;
Line 654... Line 669...
654
		stream << "CONFIG:ROOM:" << itostring(akt->rnum) << ":" << string(akt->rname) << ":" <<
669
		stream << "CONFIG:ROOM:" << itostring(akt->rnum) << ":" << string(akt->rname) << ":" <<
655
			fixed << setprecision(1) << akt->soll << ":" << akt->night << ":" <<
670
			fixed << setprecision(1) << akt->soll << ":" << akt->night << ":" <<
656
			akt->minimal << ":" << timeToStr(akt->start) << ":" << timeToStr(akt->end) << ":" <<
671
			akt->minimal << ":" << timeToStr(akt->start) << ":" << timeToStr(akt->end) << ":" <<
657
			timeToStr(akt->wstart) << ":" << timeToStr(akt->wend) << ";";
672
			timeToStr(akt->wstart) << ":" << timeToStr(akt->wend) << ";";
658
 
673
 
-
 
674
		stream << "HEATING:" << itostring(akt->rnum) << ":";
-
 
675
 
-
 
676
		if (akt->valve)
-
 
677
			stream << "ON;";
-
 
678
		else
-
 
679
			stream << "OFF;";
-
 
680
 
659
		akt = akt->next;
681
		akt = akt->next;
660
	}
682
	}
661
 
683
 
662
	write(s1, stream.str().c_str(), stream.str().length());
684
	write(s1, stream.str().c_str(), stream.str().length());
663
}
685
}
Line 810... Line 832...
810
				akt->wend = strToTime(hv1);
832
				akt->wend = strToTime(hv1);
811
				debug("WorkEndTime: " + itostring(akt->wend) + "(" + ToString(hv1) + ")");
833
				debug("WorkEndTime: " + itostring(akt->wend) + "(" + ToString(hv1) + ")");
812
			}
834
			}
813
		}
835
		}
814
	}
836
	}
-
 
837
 
-
 
838
	akt = HeatConf;
-
 
839
	time_t loctime = getTime();
-
 
840
 
-
 
841
	while (akt)
815
	
842
	{
-
 
843
		if (onoff)
-
 
844
			akt->status = OFF;
-
 
845
		else if (loctime > akt->start && loctime < akt->end)
-
 
846
			akt->status = NORMAL;
-
 
847
		else
-
 
848
			akt->status = NIGHT;
-
 
849
 
-
 
850
		akt = akt->next;
-
 
851
	}
-
 
852
 
816
	cfile.close ();
853
	cfile.close ();
817
	return true;
854
	return true;
818
}
855
}
819
 
856
 
820
 
857
 
Line 956... Line 993...
956
			syslog(LOG_DAEMON, "Error opening database %s: %s", Configure.home, sqlite3_errmsg(db));
993
			syslog(LOG_DAEMON, "Error opening database %s: %s", Configure.home, sqlite3_errmsg(db));
957
			return false;
994
			return false;
958
		}
995
		}
959
 
996
 
960
		akt = HeatConf;
997
		akt = HeatConf;
-
 
998
		time_t loctime = getTime();
961
 
999
 
962
		while (akt)
1000
		while (akt)
963
		{
1001
		{
964
			debug("Queriing "+itostring(akt->rnum)+", "+ToString(akt->rname));
1002
			debug("Queriing "+itostring(akt->rnum)+", "+ToString(akt->rname));
965
			query = "select id, name, soll, night, minimal, start, end from heating where id = "+itostring(akt->rnum);
1003
			query = "select id, name, soll, night, minimal, start, end from heating where id = "+itostring(akt->rnum);
Line 999... Line 1037...
999
				tb->heat = sqlite3_column_int(res, 3);
1037
				tb->heat = sqlite3_column_int(res, 3);
1000
				debug("KITABLE: read "+itostring(sqlite3_column_int(res, 0)));
1038
				debug("KITABLE: read "+itostring(sqlite3_column_int(res, 0)));
1001
			}
1039
			}
1002
 
1040
 
1003
			sqlite3_finalize(res);
1041
			sqlite3_finalize(res);
-
 
1042
 
-
 
1043
			if (onoff)
-
 
1044
				akt->status = OFF;
-
 
1045
			else if (loctime > akt->start && loctime < akt->end)
-
 
1046
				akt->status = NORMAL;
-
 
1047
			else
-
 
1048
				akt->status = NIGHT;
-
 
1049
 
1004
			akt = akt->next;
1050
			akt = akt->next;
1005
		}
1051
		}
1006
 
1052
 
1007
		debug("Reading global parameters from SQL3 database");
1053
		debug("Reading global parameters from SQL3 database");
1008
		query = "select night, minimal, onoff from glbheat";
1054
		query = "select night, minimal, onoff from glbheat";
Line 1095... Line 1141...
1095
	return zeit;
1141
	return zeit;
1096
}
1142
}
1097
 
1143
 
1098
time_t heating::getTime()
1144
time_t heating::getTime()
1099
{
1145
{
1100
tm *ltm, ptm;
1146
tm *ltm;
1101
time_t t = time(NULL);
1147
time_t t = time(NULL);
-
 
1148
time_t out;
1102
 
1149
 
1103
	ltm = localtime(&t);
1150
	ltm = localtime(&t);
1104
	memset (&ptm, 0, sizeof(struct tm));
-
 
1105
	ptm.tm_hour = ltm->tm_hour;
1151
	out = (time_t)(ltm->tm_hour * 3600 + ltm->tm_min * 60 + ltm->tm_sec);
1106
	ptm.tm_min = ltm->tm_min;
-
 
1107
	ptm.tm_isdst = ltm->tm_isdst;
-
 
1108
	return mktime(&ptm);
1152
	return out;
1109
}
1153
}
1110
 
1154
 
1111
heating::HCONF* heating::appendHConf()
1155
heating::HCONF* heating::appendHConf()
1112
{
1156
{
1113
HCONF *akt, *p;
1157
HCONF *akt, *p;
1114
 
1158
 
1115
	akt = new HCONF;
1159
	akt = new HCONF;
1116
	memset(akt, 0, sizeof(HCONF));
1160
	memset(akt, 0, sizeof(HCONF));
-
 
1161
	akt->soll = 0.0;
-
 
1162
	akt->night = 0.0;
-
 
1163
	akt->minimal = 0.0;
-
 
1164
	akt->ist = 0.0;
1117
 
1165
 
1118
	if (HeatConf == nullptr)
1166
	if (HeatConf == nullptr)
1119
		HeatConf = akt;
1167
		HeatConf = akt;
1120
	else
1168
	else
1121
	{
1169
	{
Line 1169... Line 1217...
1169
 
1217
 
1170
		akt = akt->next;
1218
		akt = akt->next;
1171
	}
1219
	}
1172
 
1220
 
1173
	if (!akt)
1221
	if (!akt)
-
 
1222
	{
-
 
1223
		syslog(LOG_WARNING, "evaluateTemp: Room %s not found!", room);
1174
		return false;
1224
		return false;
-
 
1225
	}
1175
 
1226
 
1176
	loctime = getTime();
1227
	loctime = getTime();
1177
 
1228
 
1178
	switch(akt->status)
1229
	switch(akt->status)
1179
	{
1230
	{