PROCESS_THREAD(test_sht11_process, ev, data) { static unsigned rh; static struct etimer et; PROCESS_BEGIN(); sht11_init(); for(etimer_set(&et,CLOCK_SECOND*30);;etimer_reset(&et)){ PROCESS_YIELD(); printf("Temperature: %u degree Celsius\n", (-39.60 + 0.01 * sht11_temp())); rh = sht11_humidity(); printf("Relative Humidity: %u%%\n", (unsigned)(-4 + 0.0405*rh - 2.8e-6*(rh*rh))); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ static int value(int type) { switch(type) { /* Photosynthetically Active Radiation. */ case SHT11_SENSOR_TEMP: return sht11_temp();; break; /* Total Solar Radiation. */ case SHT11_SENSOR_HUMIDITY: return sht11_humidity(); break; case SHT11_SENSOR_BATTERY_INDICATOR: return sht11_sreg() & 0x40? 1: 0; } return 0; }
/*---------------------------------------------------数据采集上传模考---------------------------------------------*/ static void udp_send_data(struct udp_tx *udp_tx_info) { static char pdata_buf[20]; char data_buf[3]; #if sht11 float tc,hc; sht11_init(); unsigned int tempera = sht11_temp(); unsigned int humidity = sht11_humidity(); tc=sht11_TemperatureC(tempera); hc=sht11_Humidity(tempera,humidity); printf("sorce Tc:%d;Hc:%d\n",(int)tc,(int)hc); // tc=25.5; // hc=57.2; printf("Tc:%d;Hc:%d\n",(int)tc,(int)hc); pdata_buf[0]=0x02; sprintf(data_buf,"%d",(int)tc); memcpy(&pdata_buf[1],data_buf,3); pdata_buf[4]=0x03; sprintf(data_buf,"%d",(int)hc); memcpy(&pdata_buf[5],data_buf,3); // sprintf(temp_data_buf,"%d.%d",(int)hc,((int)(hc*10))%10); printf("temp_data:%s\n",pdata_buf); #endif #if sensor int16_t temperature; temperature = sensor_temp_get(TEMP_UNIT_CELCIUS); pdata_buf[0]=0x02; sprintf(data_buf,"%d",temperature); memcpy(&pdata_buf[1],data_buf,3); printf("temp_data:%s\n",pdata_buf); #endif #if light_sensor int16_t illumination; illumination=60; // modbus_init(); // illumination= modbus_get(); printf("illumination_data:%d\n",illumination); data_buf[0]=0x00; data_buf[1]=0xff&(illumination>>8); data_buf[2]=0xff&illumination; pdata_buf[0]=0x04; memcpy(&pdata_buf[1],data_buf,3); printf("temp_data:%s\n",pdata_buf); #endif #if bh1750_sensor int16_t illumination; illumination=60; bh1750_init(); illumination= bh1750_light(); printf("illumination_data:%d\n",illumination); data_buf[0]=0x00; data_buf[1]=0xff&(illumination>>8); data_buf[2]=0xff&illumination; pdata_buf[0]=0x04; memcpy(&pdata_buf[1],data_buf,3); printf("temp_data:%s\n",pdata_buf); #endif uint8_t sum = 0; udp_tx_info->buf[0] = udp_header[0]; udp_tx_info->buf[1] = udp_header[1]; udp_tx_info->buf[2] =version[0]; udp_tx_info->buf[3] = DATA_SEND ; //0x01 udp_tx_info->buf[4]=user.userid[3]; udp_tx_info->buf[5]=user.userid[2]; udp_tx_info->buf[6]=user.userid[1]; udp_tx_info->buf[7]=user.userid[0]; udp_tx_info->buf[8] = K-8; memcpy(&udp_tx_info->buf[9],udp_id,K-8); memcpy(&udp_tx_info->buf[K+1],device_type,4); udp_tx_info->buf[K+5] = 0x00; udp_tx_info->buf[K+6] = 0x14; memcpy(&udp_tx_info->buf[K+7],pdata_buf,20); sum = calac_checksum(udp_tx_info); udp_tx_info->buf[K+27] = sum; udp_tx_info->buf[K+28] = 0x0D; udp_tx_info->buf[K+29] = 0x0A; udp_tx_info->len = K+30; }