refactor ♻️: Implement comprehensive sensor system for environmental monitoring, including temperature, humidity, pressure, wind speed, and direction.
- This commit updates the build process to use a custom toolchain and configuration, enabling compilation of multiple project components. - The primary goal of this commit is to provide a detailed overview and documentation for a zigbee weather station project, including firmware information and sensor component descriptions. - Updated configuration file with new constants and definitions. - The MAIN GOAL of these changes is to implement a comprehensive sensor system for environmental monitoring, including temperature, humidity, pressure, wind speed, and direction. - Main goal of the changes: Define a new header file with function prototypes and external variable declarations. - Added new functionality to initialize and read data from an anemometer sensor, introducing its necessary setup and calculation logic. - Added header file for anemometer sensor with function prototypes. - Initial implementation of BME280 sensor functionality. - Added function prototype for the BME280 initialization and data reading functions. - Initializes and configures a rain gauge sensor with GPIO interrupt setup. - Added function prototypes to the rain gauge sensor header file. - This commit adds a new C function to initialize and read data from a wind vane sensor. - Updated header file with new function prototype definitions. - This commit adds a new function `send_zigbee_data` to send various Zigbee data types. - Added Zigbee communication header file with function prototype for sending data.
This commit is contained in:
14
Makefile
Normal file
14
Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
CC = msp430-gcc
|
||||
CFLAGS = -Wall -Os
|
||||
LIBS = -lZStack -lhal
|
||||
|
||||
SRCS = main.c zigbee_comm.c sensors/bme280.c sensors/wind_vane.c sensors/rain_gauge.c sensors/anemometer.c
|
||||
HEADERS = main.h zigbee_comm.h sensors/bme280.h sensors/wind_vane.h sensors/rain_gauge.h sensors/anemometer.h config.h
|
||||
|
||||
all: main
|
||||
|
||||
main: $(SRCS) $(HEADERS)
|
||||
$(CC) $(CFLAGS) $(SRCS) $(LIBS) -o main.elf
|
||||
|
||||
clean:
|
||||
rm -f main.elf
|
||||
41
README.md
41
README.md
@@ -1,2 +1,43 @@
|
||||
# zigbee_weather_station
|
||||
|
||||
firmware for CC2530
|
||||
|
||||
zigbee weather station using sensors from WH-SP-WS02
|
||||
|
||||
Overview of Components:
|
||||
|
||||
- BME280: Measures temperature, humidity, and pressure.
|
||||
- Tipping Bucket: Measures rainfall with each tip corresponding to 0.2794 mm.
|
||||
- Anemometer: Measures wind speed, with each tip corresponding to 1.492 mph.
|
||||
- Wind Vane: A resistive sensor with 16 positions that can indicate wind direction.
|
||||
|
||||
Libraries and Tools:
|
||||
- Z-Stack (Zigbee Stack): The CC2530 uses the Z-Stack firmware for Zigbee. This provides the Zigbee protocol stack and the tools to create Zigbee devices.
|
||||
- I2C for BME280: You'll need the I2C interface to communicate with the BME280.
|
||||
- GPIO for Tipping Bucket, Anemometer, and Wind Vane: These sensors can be read using the GPIO pins, either as interrupts or polling.
|
||||
|
||||
|
||||
|
||||
/project-folder
|
||||
├── main.c // Main application code
|
||||
├── main.h // Header file for main
|
||||
│
|
||||
├── zigbee_comm.c // Zigbee communication functions
|
||||
├── zigbee_comm.h // Header for Zigbee communication functions
|
||||
│
|
||||
├── sensors // Directory for sensor-related files
|
||||
│ ├── bme280.c // BME280 sensor driver
|
||||
│ ├── bme280.h // Header for BME280 sensor
|
||||
│ ├── wind_vane.c // Wind Vane sensor driver
|
||||
│ ├── wind_vane.h // Header for Wind Vane sensor
|
||||
│ ├── rain_gauge.c // Rain Gauge sensor driver
|
||||
│ ├── rain_gauge.h // Header for Rain Gauge sensor
|
||||
│ └── anemometer.c // Anemometer sensor driver
|
||||
│ └── anemometer.h // Header for Anemometer sensor
|
||||
│
|
||||
├── config // Configuration settings
|
||||
│ └── config.h // Configuration file for settings (timing, thresholds, etc.)
|
||||
│
|
||||
└── Makefile // Makefile for compiling the project
|
||||
│
|
||||
└── README.md (Project description and instructions)
|
||||
7
config.h
Normal file
7
config.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
// Configuration values
|
||||
#define SENSOR_READ_INTERVAL 60000 // 60 seconds in ms
|
||||
|
||||
#endif // CONFIG_H
|
||||
63
main.c
Normal file
63
main.c
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <ioCC2530.h>
|
||||
#include "hal_types.h"
|
||||
#include "hal_timer.h"
|
||||
#include "ZComDef.h"
|
||||
#include "OSAL.h"
|
||||
#include "ZStack.h"
|
||||
#include "bme280.h"
|
||||
#include "wind_vane.h"
|
||||
#include "rain_gauge.h"
|
||||
#include "anemometer.h"
|
||||
#include "zigbee_comm.h"
|
||||
#include "config.h"
|
||||
|
||||
// Global variables to store sensor data
|
||||
uint8 zcl_temp_humidity_data[6]; // For temperature, humidity, pressure
|
||||
uint8 zcl_wind_data[2]; // For wind speed, wind direction
|
||||
|
||||
// Initialize all sensors
|
||||
void init_sensors() {
|
||||
BME280_init();
|
||||
WindVane_init();
|
||||
RainGauge_init();
|
||||
Anemometer_init();
|
||||
}
|
||||
|
||||
// Read sensor data and store it
|
||||
void read_sensor_data() {
|
||||
int32 temperature, humidity, pressure;
|
||||
BME280_readData(&temperature, &humidity, &pressure);
|
||||
|
||||
// Store BME280 data
|
||||
zcl_temp_humidity_data[0] = (uint8)(temperature >> 8);
|
||||
zcl_temp_humidity_data[1] = (uint8)(temperature & 0xFF);
|
||||
zcl_temp_humidity_data[2] = (uint8)(humidity >> 8);
|
||||
zcl_temp_humidity_data[3] = (uint8)(humidity & 0xFF);
|
||||
zcl_temp_humidity_data[4] = (uint8)(pressure >> 8);
|
||||
zcl_temp_humidity_data[5] = (uint8)(pressure & 0xFF);
|
||||
|
||||
// Read and store wind data
|
||||
zcl_wind_data[0] = WindVane_read(); // Wind direction
|
||||
zcl_wind_data[1] = Anemometer_read(); // Wind speed
|
||||
|
||||
// Read rain gauge data
|
||||
RainGauge_read();
|
||||
}
|
||||
|
||||
// Main application loop
|
||||
void main_loop() {
|
||||
while (1) {
|
||||
read_sensor_data(); // Read all sensor data
|
||||
send_zigbee_data(); // Send collected data over Zigbee
|
||||
|
||||
osal_delay(60000); // Delay for 1 minute (60000ms)
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
hal_init(); // Initialize the CC2530 hardware
|
||||
init_sensors(); // Initialize all sensors
|
||||
main_loop(); // Enter main loop
|
||||
|
||||
return 0;
|
||||
}
|
||||
12
main.h
Normal file
12
main.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
// Function prototypes
|
||||
void init_sensors();
|
||||
void read_sensor_data();
|
||||
void main_loop();
|
||||
|
||||
extern uint8 zcl_temp_humidity_data[6]; // For BME280 data
|
||||
extern uint8 zcl_wind_data[2]; // For wind data (speed, direction)
|
||||
|
||||
#endif // MAIN_H
|
||||
12
sensors/anemometer.c
Normal file
12
sensors/anemometer.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "anemometer.h"
|
||||
|
||||
// Initialize anemometer (GPIO, interrupts, etc.)
|
||||
void Anemometer_init() {
|
||||
// Set up GPIO for anemometer
|
||||
}
|
||||
|
||||
// Read wind speed (in mph or other units)
|
||||
uint8 Anemometer_read() {
|
||||
// Read wind speed value (e.g., 1.492 mph per tip)
|
||||
return wind_speed;
|
||||
}
|
||||
8
sensors/anemometer.h
Normal file
8
sensors/anemometer.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef ANEMOMETER_H
|
||||
#define ANEMOMETER_H
|
||||
|
||||
// Function prototypes
|
||||
void Anemometer_init();
|
||||
uint8 Anemometer_read();
|
||||
|
||||
#endif // ANEMOMETER_H
|
||||
11
sensors/bme280.c
Normal file
11
sensors/bme280.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "bme280.h"
|
||||
|
||||
// Initialize BME280 sensor (I2C setup, etc.)
|
||||
void BME280_init() {
|
||||
// Initialize I2C, configure BME280 settings, etc.
|
||||
}
|
||||
|
||||
// Read data from BME280 sensor (temperature, humidity, pressure)
|
||||
void BME280_readData(int32* temperature, int32* humidity, int32* pressure) {
|
||||
// Read temperature, humidity, and pressure data from BME280 via I2C
|
||||
}
|
||||
8
sensors/bme280.h
Normal file
8
sensors/bme280.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef BME280_H
|
||||
#define BME280_H
|
||||
|
||||
// Function prototypes
|
||||
void BME280_init();
|
||||
void BME280_readData(int32* temperature, int32* humidity, int32* pressure);
|
||||
|
||||
#endif // BME280_H
|
||||
12
sensors/rain_gauge.c
Normal file
12
sensors/rain_gauge.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "rain_gauge.h"
|
||||
|
||||
// Initialize rain gauge (configure GPIO interrupts or polling)
|
||||
void RainGauge_init() {
|
||||
// Set up the GPIO pin for the rain gauge
|
||||
}
|
||||
|
||||
// Read rain gauge data (check if bucket tipped)
|
||||
uint8 RainGauge_read() {
|
||||
// Return rain tip count or trigger status
|
||||
return rain_tip;
|
||||
}
|
||||
8
sensors/rain_gauge.h
Normal file
8
sensors/rain_gauge.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef RAIN_GAUGE_H
|
||||
#define RAIN_GAUGE_H
|
||||
|
||||
// Function prototypes
|
||||
void RainGauge_init();
|
||||
uint8 RainGauge_read();
|
||||
|
||||
#endif // RAIN_GAUGE_H
|
||||
12
sensors/wind_vane.c
Normal file
12
sensors/wind_vane.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "wind_vane.h"
|
||||
|
||||
// Initialize the wind vane (configure GPIOs, etc.)
|
||||
void WindVane_init() {
|
||||
// Initialize GPIO for wind vane
|
||||
}
|
||||
|
||||
// Read wind direction (0-15 for 16 positions)
|
||||
uint8 WindVane_read() {
|
||||
// Read the wind direction from the wind vane sensor
|
||||
return wind_direction;
|
||||
}
|
||||
8
sensors/wind_vane.h
Normal file
8
sensors/wind_vane.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef WIND_VANE_H
|
||||
#define WIND_VANE_H
|
||||
|
||||
// Function prototypes
|
||||
void WindVane_init();
|
||||
uint8 WindVane_read();
|
||||
|
||||
#endif // WIND_VANE_H
|
||||
13
zigbee_comm.c
Normal file
13
zigbee_comm.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "zigbee_comm.h"
|
||||
#include "ZStack.h"
|
||||
|
||||
// Function to send Zigbee data (temperature, humidity, pressure, wind data, rain data)
|
||||
void send_zigbee_data() {
|
||||
// Send BME280 data (temperature, humidity, pressure)
|
||||
ZStack_SendData(zcl_temp_humidity_data, sizeof(zcl_temp_humidity_data));
|
||||
|
||||
// Send wind data (wind direction, wind speed)
|
||||
ZStack_SendData(zcl_wind_data, sizeof(zcl_wind_data));
|
||||
|
||||
// You can also add any other data here (rain data, etc.)
|
||||
}
|
||||
7
zigbee_comm.h
Normal file
7
zigbee_comm.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef ZIGBEE_COMM_H
|
||||
#define ZIGBEE_COMM_H
|
||||
|
||||
// Function prototypes
|
||||
void send_zigbee_data();
|
||||
|
||||
#endif // ZIGBEE_COMM_H
|
||||
Reference in New Issue
Block a user