Exemplo n.º 1
0
void service_handler( ConnectionState_t* pConnectionState )
{
  enum Service service = none;
  http_server_get_query_variable(pConnectionState, "which",buffer, BUFF_SIZE);
  
  LOG_DBG("which=%s\n",buffer);
  
  if ( !strcmp(buffer,"temperature") )
  {
    service = temperature;
  }
  else if ( !strcmp(buffer,"light") )
  {
    service = light;
  }
  else
  {
    http_server_set_http_status( pConnectionState, CLIENT_ERROR_BAD_REQUEST );
    return;
  }
  
  XmlWriter xmlWriter;

  simpleXmlStartDocument(&xmlWriter, http_server_get_res_buf(pConnectionState), RESPONSE_BUFFER_SIZE);
  simpleXmlStartElement(&xmlWriter, NULL, "Service");
  simpleXmlStartElement(&xmlWriter, NULL, "Name");
  simpleXmlCharacters(&xmlWriter, buffer);
  simpleXmlEndElement(&xmlWriter, NULL, "Name");
  simpleXmlStartElement(&xmlWriter, NULL, "Value");

  uint16_t value = 0;
  if ( service == temperature )
  {
    #ifdef CONTIKI_TARGET_SKY
      value = sht11_temp();

      snprintf(buffer, sizeof(buffer),
       "%d.%d", (value / 10 - 396) / 10, (value / 10 - 396) % 10);
     #else
      snprintf(buffer, sizeof(buffer),
       "%d.%d", value, value);
     #endif
  }
  else
  {
    #ifdef CONTIKI_TARGET_SKY
      value = sensors_light1();
    #endif

    snprintf(buffer, sizeof(buffer), "%d", value);
  }

  simpleXmlCharacters(&xmlWriter, buffer);
  simpleXmlEndElement(&xmlWriter, NULL, "Value");
  simpleXmlEndElement(&xmlWriter, NULL, "Service");
  simpleXmlEndDocument(&xmlWriter);
  
  http_server_set_representation(pConnectionState, TEXT_XML );
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------*/
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;
}
Exemplo n.º 3
0
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();
}
Exemplo n.º 4
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;
}