'; $content .= sprintf( __( 'Sorry, the device "%s" has not been found. Please check your device name for accuracy e.g. extra spaces at the end, and try again.', 'aq-data-foobot' ), esc_html( $device_name ) ); $content .= ''; return $content; } // Fetch the sensor data from the database $sensor_data = bd_foobot_fetch_db_sensors( $uuid ); if ( count( $sensor_data ) > 0 ) { // Remove one level from the array $data = $sensor_data[0]; // Data time & date $utc_timestamp = ''; if ( isset( $data['timestamp'] ) ) { $utc_timestamp = $data['timestamp']; $local_timestamp = bd324_get_local_datetime( $utc_timestamp ); } // Pretty up the data $Tmp_data = number_format( $data['datapointTmp'], 1 ); $Pm_data = round( $data['datapointPm'], 0 ); $Co2_data = round( $data['datapointCo2'], 0 ); $Voc_data = round( $data['datapointVoc'], 0 ); $Hum_data = round( $data['datapointHum'], 1 ); $All_data = round( $data['datapointAllpollu'], 0 ); // Output sensor data $content = '
'; // Show device name and timestamp if ( $utc_timestamp ) { $content .= sprintf( __( '
Data from %1$s updated %2$s
', 'aq-data-foobot' ), esc_html( $device_name ), esc_html( $local_timestamp ) ); } $content .= '
'; } else { // Error message $content = '
'; $content .= sprintf( __( 'The requested device has been found ("%1$s" UUID %2$s), but no data has been sent. Please confirm your device is working via the Foobot app or dashboard.', 'aq-data-foobot' ), esc_html( $device_name ), esc_html( $uuid ) ); $content .= '
'; } return $content; } /** * Get current temperature and return it as array */ function bd_get_temp_now( $uuid ) { /** * First, we need to check our transient and update the data in the * custom table if necessary. */ bd_foobot_update_sensor_data( $uuid ); /** * Having done that, we can proceed with questioning the database. */ $data = bd_foobot_fetch_latest_sensor_data(); return $data; }