SPHERE_MT3620/AirQuality5_demo/AvnetSphereAirQuality5/main.c
/// <summary>
///     Print latest data from on-board sensors.
/// </summary>

Print latest data from on-board sensors.
Print latest data from on - board sensors .
void AcqTimerEventHandler(EventData *eventData)
{
	uint16_t cha0;
	uint16_t cha1;
	uint16_t cha2;
	float v0;
	float v1;
	float v2;
	float Rs_NO2;
	float Rs_NH3;
	float Rs_CO;
	float ppm_CO;
	float ppm_NO2;
	float ppm_NH3;
#if (defined(IOT_CENTRAL_APPLICATION) || defined(IOT_HUB_APPLICATION))
	static bool firstPass = true;
#endif
	if (ConsumeTimerFdEvent(acquirePollTimerFd) != 0) 
	{
		terminationRequired = true;
		return;
	}
	Log_Debug("R0 CO: %d \n", user_r0_co);
	Log_Debug("R0 NO2: %d \n", user_r0_no2);
	Log_Debug("R0 NH3: %d \n", user_r0_nh3);
	cha0 = read_gas(CH_NO2);
	cha1 = read_gas(CH_NH3);
	cha2 = read_gas(CH_CO);
	Log_Debug("ADC channel0: %d\n", cha0);
	Log_Debug("ADC channel1: %d\n", cha1);
	Log_Debug("ADC channel2: %d\n", cha2);
	v0 = read_voltage(CH_NO2);
	v1 = read_voltage(CH_NH3);
	v2 = read_voltage(CH_CO);
	Log_Debug("Voltage channel0: %.3f\n", v0);
	Log_Debug("Voltage channel1: %.3f\n", v1);
	Log_Debug("Voltage channel2: %.3f\n", v2);
	Rs_NO2 = read_resistance(CH_NO2);
	Rs_NH3 = read_resistance(CH_NH3);
	Rs_CO = read_resistance(CH_CO);
	Log_Debug("Rs NO2: %.3f\n", Rs_NO2);
	Log_Debug("Rs NH3: %.3f\n", Rs_NH3);
	Log_Debug("Rs CO: %.3f\n", Rs_CO);
	ppm_NO2 = read_concentration(CH_NO2);
	Log_Debug("NO2 ppm: %.3f\n", ppm_NO2);
	ppm_NH3 = read_concentration(CH_NH3);
	Log_Debug("NH3 ppm: %.3f\n", ppm_NH3);
	ppm_CO = read_concentration(CH_CO);
	Log_Debug("CO ppm: %.3f\n", ppm_CO);
	Log_Debug("\n");
	lcd_setCursor(0, 1);
	lcd_printf("CO:%.2f NH3:%.2f", ppm_CO, ppm_NH3);
	lcd_setCursor(0, 0);
	lcd_printf("NO2:%.2f", ppm_NO2);
#if (defined(IOT_CENTRAL_APPLICATION) || defined(IOT_HUB_APPLICATION))
	if (!firstPass)
	{
		char *pjsonBuffer = (char *)malloc(JSON_BUFFER_SIZE);
		if (pjsonBuffer == NULL) 
		{
			Log_Debug("ERROR: not enough memory to send telemetry");
		}
		snprintf(pjsonBuffer, JSON_BUFFER_SIZE, "{\"CO_ppm\":\"%.2f\", \"NO2_ppm\":\"%.2f\", \"NH3_ppm\":\"%.2f\", \"Rs_CO\": \"%.2f\", \"Rs_NO2\": \"%.2f\", \"Rs_NH3\": \"%.2f\"}",
			ppm_CO, ppm_NO2, ppm_NH3, Rs_CO, Rs_NO2, Rs_NH3);
		Log_Debug("\n[Info] Sending telemetry: %s\n", pjsonBuffer);
		AzureIoT_SendMessage(pjsonBuffer);
		free(pjsonBuffer);
	}
	firstPass = false;
#endif 
}
void AcqTimerEventHandler ( EventData * eventData ) { uint16_t cha0 ; uint16_t cha1 ; uint16_t cha2 ; float v0 ; float v1 ; float v2 ; float Rs_NO2 ; float Rs_NH3 ; float Rs_CO ; float ppm_CO ; float ppm_NO2 ; float ppm_NH3 ; #if ( defined ( IOT_CENTRAL_APPLICATION ) || defined ( IOT_HUB_APPLICATION ) ) static bool firstPass = true ; #endif if ( ConsumeTimerFdEvent ( acquirePollTimerFd ) != 0 ) { terminationRequired = true ; return ; } Log_Debug ( " \n " , user_r0_co ) ; Log_Debug ( " \n " , user_r0_no2 ) ; Log_Debug ( " \n " , user_r0_nh3 ) ; cha0 = read_gas ( CH_NO2 ) ; cha1 = read_gas ( CH_NH3 ) ; cha2 = read_gas ( CH_CO ) ; Log_Debug ( " \n " , cha0 ) ; Log_Debug ( " \n " , cha1 ) ; Log_Debug ( " \n " , cha2 ) ; v0 = read_voltage ( CH_NO2 ) ; v1 = read_voltage ( CH_NH3 ) ; v2 = read_voltage ( CH_CO ) ; Log_Debug ( " \n " , v0 ) ; Log_Debug ( " \n " , v1 ) ; Log_Debug ( " \n " , v2 ) ; Rs_NO2 = read_resistance ( CH_NO2 ) ; Rs_NH3 = read_resistance ( CH_NH3 ) ; Rs_CO = read_resistance ( CH_CO ) ; Log_Debug ( " \n " , Rs_NO2 ) ; Log_Debug ( " \n " , Rs_NH3 ) ; Log_Debug ( " \n " , Rs_CO ) ; ppm_NO2 = read_concentration ( CH_NO2 ) ; Log_Debug ( " \n " , ppm_NO2 ) ; ppm_NH3 = read_concentration ( CH_NH3 ) ; Log_Debug ( " \n " , ppm_NH3 ) ; ppm_CO = read_concentration ( CH_CO ) ; Log_Debug ( " \n " , ppm_CO ) ; Log_Debug ( " \n " ) ; lcd_setCursor ( 0 , 1 ) ; lcd_printf ( " " , ppm_CO , ppm_NH3 ) ; lcd_setCursor ( 0 , 0 ) ; lcd_printf ( " " , ppm_NO2 ) ; #if ( defined ( IOT_CENTRAL_APPLICATION ) || defined ( IOT_HUB_APPLICATION ) ) if ( ! firstPass ) { char * pjsonBuffer = ( char * ) malloc ( JSON_BUFFER_SIZE ) ; if ( pjsonBuffer == NULL ) { Log_Debug ( " " ) ; } snprintf ( pjsonBuffer , JSON_BUFFER_SIZE , " \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" \" " , ppm_CO , ppm_NO2 , ppm_NH3 , Rs_CO , Rs_NO2 , Rs_NH3 ) ; Log_Debug ( " \n \n " , pjsonBuffer ) ; AzureIoT_SendMessage ( pjsonBuffer ) ; free ( pjsonBuffer ) ; } firstPass = false ; #endif }
<summary>
Print latest data from on-board sensors.
<summary > Print latest data from on - board sensors .
// Variables for capturing sensor data // Consume the event.  If we don't do this we'll come right back  // to process the same event again // Print R0 data // Print ADC data and sensor data // Print sensor concentrations //// LCD printing // Print concentration on LCD mini // Add extra spaces to erase previous characters(this is faster than lcd_clearDisplay) //// end LCD printing // We've seen that the first read of the Accelerometer data is garbage.  If this is the first pass // reading data, don't report it to Azure.  Since we're graphing data in Azure, this data point // will skew the data. // Allocate memory for a telemetry message to Azure // construct the telemetry message