How can I build a GUI for my weather station ? I need help to understand how to read valors in an user interface and what can I use to create it .
A GUI running on what platform?
Do you have a working weather station that collects info, at this time?
MacOS or Windows
Do you know any python?
Writing a script to receive serial data in python is trivial. Then just add some tkinter widgets to display the data neatly and you're good to go with a fully portable GUI.
so if I have my code on my arduino board and it's reading in serial com , all that I need to do is to create in python a simple GUI that is reading that serial data like for example if one of my parameteres is "windspeed" in arduino code I am using the same with print ( "Windspeed id " , windspeed )
Yes.
Yes!
YES!!!
You can use Python to read the serial ports. If your doing the wireless thing with your MCU's you could use MQTT and Node-Red to display the info on the screen.
Here is some ESP32 MQTT do the weather station thingy code:
/*
Project, use solar cells to generate power
2/2/2020
*/
#include <WiFi.h>
#include <PubSubClient.h>
#include "certs.h"
#include "sdkconfig.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#include "freertos/event_groups.h"
#include "esp_sleep.h"
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
////
EventGroupHandle_t eg;
#define evtDoBME ( 1 << 2 )
#define evtSetupBME_Complete ( 1 << 3 )
SemaphoreHandle_t sema_ReadBME680;
////////
WiFiClient wifiClient;
PubSubClient MQTTclient(mqtt_server, mqtt_port, wifiClient);
//////
Adafruit_BME680 bme( GPIO_NUM_5 );
///
// RTC_DATA_ATTR int t_Difference = 0;
////
void setup()
{
eg = xEventGroupCreate();
sema_ReadBME680 = xSemaphoreCreateBinary();
xTaskCreatePinnedToCore( fDoBME, "fDoBME", 20000, NULL, 3, NULL, 1 ); // assigned to core
//start this task last
xTaskCreatePinnedToCore( fDoTheThing, "fDoTheThing", 40000, NULL, 5, NULL, 1 ); // assigned to core
} // end setup()
////
void connectToMQTT()
{
// create client ID from mac address
byte mac[5];
WiFi.macAddress(mac); // get mac address
String clientID = String(mac[0]) + String(mac[4]) ; // use mac address to create clientID
while ( !MQTTclient.connected() )
{
// boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);
MQTTclient.connect( clientID.c_str(), mqtt_username, mqtt_password, NULL ,1, true, NULL );
// MQTTclient.connect( clientID.c_str(), mqtt_username, mqtt_password );
vTaskDelay( 250 );
}
log_i("MQTT Connected");
}
//
void connectToWiFi()
{
int i = 0;
while ( WiFi.status() != WL_CONNECTED )
{
WiFi.disconnect();
WiFi.begin( SSID, PWD );
vTaskDelay( 4000 );
i++;
if ( i == 3 )
{
ESP.restart();
}
}
}
////
void fDoTheThing( void * pvParameters )
{
xEventGroupWaitBits (eg, evtSetupBME_Complete, pdTRUE, pdTRUE, portMAX_DELAY ); //
connectToWiFi();
connectToMQTT();
while (1)
{
vTaskDelay( 1000 );
xEventGroupSetBits( eg, evtDoBME ); // trigger tasks
xSemaphoreTake( sema_ReadBME680, portMAX_DELAY ); // wait for task to be done
MQTTclient.disconnect();
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
//esp_sleep_enable_timer_wakeup( 1000000 * (60 * 6) ); //6minute sleep time
// esp_sleep_enable_timer_wakeup( (1000000 * (60 * 3)) - 4000000 ); //3 minute sleep time - 4 seconds
//esp_sleep_enable_timer_wakeup( 1000000 * (60 * 5) ); //5 minute sleep time
// esp_sleep_enable_timer_wakeup( 1000000 * (60) ); // 1 minute slep time for troubleshooting, drains battery.
esp_sleep_enable_timer_wakeup( (1000000 * (60))/5 );
esp_deep_sleep_start();
} //while(1)
vTaskDelete ( NULL );
} // void fDoTheThing( void * pvParameters )
////
void fDoBME ( void *pvParameters )
{
if (!bme.begin()) {
log_i("Could not find a valid BME680 sensor, check wiring!");
while (1);
}
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
float fTemperature = 0.0f;
float fPressure = 0.0f;
float fHumidity = 0.0f;
uint32_t iGasResistance = 0;
xEventGroupSetBits( eg, evtSetupBME_Complete ); // trigger task to begin
for ( ;; )
{
xEventGroupWaitBits (eg, evtDoBME, pdTRUE, pdTRUE, portMAX_DELAY ); //
//log_i( "Signal strength %d ", WiFi.RSSI() );
fTemperature = bme.readTemperature();
fTemperature = (fTemperature * 1.8f) + 32.0f; // (Celsius x 1.8) + 32
fPressure = bme.readPressure();
fPressure = fPressure / 133.3223684f; //converts to mmHg
fHumidity = bme.readHumidity();
iGasResistance = bme.readGas();
log_i( "Temperature %f C, Pressure %f mmHg, Humidity %f, gasResistance %d", fTemperature, fPressure, fHumidity, iGasResistance );
MQTTclient.publish( topicOutsideTemp, String(fTemperature).c_str() );
vTaskDelay( 5 ); // gives the Raspberry Pi 4 time to receive the message and process
MQTTclient.publish( topicOutsideHumidity, String(fHumidity).c_str() );
vTaskDelay( 5 ); // no delay and RPi is still processing previous message
MQTTclient.publish( topicOutsideGasResistance, String(iGasResistance).c_str() );
vTaskDelay( 5 );
MQTTclient.publish( topicOutsidePressure, String(fPressure).c_str() );
vTaskDelay( 5 );
xSemaphoreGive ( sema_ReadBME680 );
} // for loop
vTaskDelete ( NULL );
} // void fDoBME ( void *pvParameters )
////
////
void loop() {}
////
Runs off solar.
Well your Arduino should be writing weather data to serial. You can use any language you like on the PC to read that data and display it.
Generally yes, with a caveat.
All you're sending over serial is numbers, so you need to design a simple way to know which numbers are which. There are many ways to do this.
I like to send three numbers per value when I have the luxury to do so.
- data id - what of the few types of data that you have is this particular value
- the datum - the actual value
- end number - a value chosen because it is otherwise not used, this signifies the end of the transmission
This allows you to identify the scope of the transmission and extract the correct data, which you can then display in python or any language.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.