コード例 #1
0
static  void ICACHE_FLASH_ATTR pollThermostatCb(void * arg)
{
		unsigned long epoch = sntp_time+(sntp_tz*3600);
		int year=get_year(&epoch);
		int month=get_month(&epoch,year);
		int day=day=1+(epoch/86400);
		int dow=wd(year,month,day);
		epoch=epoch%86400;
		unsigned int hour=epoch/3600;
		epoch%=3600;
		unsigned int min=epoch/60;
		int minadj = (min*100/60);
		int currtime = hour*100+minadj;
				
		if(sysCfg.thermostat1state == 0) {
			os_printf("Thermostat switched off, abandoning routine.\n");
			return;
		}
		
		long Treading=-9999;
		
		if(sysCfg.sensor_dht22_enable) { 
			struct sensor_reading* result = readDHT();
			if(result->success) {
				Treading=result->temperature*100;
				if(sysCfg.thermostat1_input==2) // Humidistat
					Treading=result->humidity*100;
			}			
		}
		else { if(sysCfg.sensor_ds18b20_enable && sysCfg.thermostat1_input==0 ) { 
			struct sensor_reading* result = read_ds18b20();
			if(result->success) {
			    int SignBit, Whole, Fract;
				Treading = result->temperature;
				
				SignBit = Treading & 0x8000;  // test most sig bit
				if (SignBit) // negative
				Treading = (Treading ^ 0xffff) + 1; // 2's comp
	
				Whole = Treading >> 4;  // separate off the whole and fractional portions
				Fract = (Treading & 0xf) * 100 / 16;

				if (SignBit) // negative
					Whole*=-1;
				Treading=Whole*100+Fract;
			}
		}//ds8b20 enabled
		}
コード例 #2
0
static ICACHE_FLASH_ATTR void MQTTbroadcastReading(void* arg){

	if(sysCfg.mqtt_enable==1) {
		//os_printf("Sending MQTT\n");
		
		if(sysCfg.sensor_dht22_enable) {
			struct sensor_reading* result = readDHT();
			if(result->success) {
				char temp[32];
				char topic[128];
				int len;
				
				dht_temp_str(temp);
				len = os_strlen(temp);
				os_sprintf(topic,"%s",sysCfg.mqtt_dht22_temp_pub_topic);
				MQTT_Publish(&mqttClient,topic,temp,len,0,0);
				os_printf("Published \"%s\" to topic \"%s\"\n",temp,topic);
				
				dht_humi_str(temp);
				len = os_strlen(temp);
				os_sprintf(topic,"%s",sysCfg.mqtt_dht22_humi_pub_topic);
				MQTT_Publish(&mqttClient,topic,temp,len,0,0);
				os_printf("Published \"%s\" to topic \"%s\"\n",temp,topic);
			}
		}
		

		if(sysCfg.sensor_ds18b20_enable) {
			struct sensor_reading* result = read_ds18b20();
			if(result->success) {
				char temp[32];
				char topic[128];
				int len;
				ds_str(temp,0);
				len = os_strlen(temp);
				os_sprintf(topic,"%s",sysCfg.mqtt_ds18b20_temp_pub_topic);
				MQTT_Publish(&mqttClient,topic,temp,len,0,0);
				os_printf("Published \"%s\" to topic \"%s\"\n",temp,topic);
			}
		}

	
    }
}