add esp8266 setup
This commit is contained in:
parent
b2c5fd4f44
commit
2cda97cbb7
33
main.c
33
main.c
|
@ -39,8 +39,9 @@
|
|||
#include "global.h" // board definitions
|
||||
#include "usart.h" // USART utilities
|
||||
#include "usb_cdcacm.h" // USB CDC ACM utilities
|
||||
#include "sensor_pzem.h" // PZEM electricity meter utilities
|
||||
//#include "sensor_pzem.h" // PZEM electricity meter utilities
|
||||
#include "sensor_sdm120.h" // SDM120 electricity meter utilities
|
||||
#include "radio_esp8266.h" // ESP8266 WiFi SoC utilities
|
||||
|
||||
/** @defgroup main_flags flag set in interrupts to be processed in main task
|
||||
* @{
|
||||
|
@ -166,18 +167,30 @@ void main(void)
|
|||
ticks_time = rtc_get_counter_val(); // get time/date from internal RTC
|
||||
printf("current time: %02lu:%02lu:%02lu\n", ticks_time/(60*60), (ticks_time%(60*60))/60, (ticks_time%60)); // display time
|
||||
|
||||
/*
|
||||
// setup PZEM electricity meter
|
||||
printf("setup PZEM-004 electricity meter: ");
|
||||
sensor_pzem_setup(); // setup PZEM electricity meter
|
||||
printf("OK\n");
|
||||
//sensor_pzem_measurement_request(0xc0a80101, SENSOR_PZEM_VOLTAGE);
|
||||
//sensor_pzem_measurement_request(0xc0a80102, SENSOR_PZEM_ADDRESS);
|
||||
sensor_pzem_measurement_request(0xc0a80101, SENSOR_PZEM_VOLTAGE);
|
||||
*/
|
||||
|
||||
// setup SDM120 electricity meter
|
||||
printf("setup SDM120 electricity meter: ");
|
||||
sensor_sdm120_setup(); // setup SDM120 electricity meter
|
||||
printf("OK\n");
|
||||
sensor_sdm120_measurement_request(1,SENSOR_SDM120_VOLTAGE);
|
||||
sensor_sdm120_measurement_request(2,SENSOR_SDM120_VOLTAGE);
|
||||
//sensor_sdm120_configuration_request(1,SENSOR_SDM120_METER_ID);
|
||||
//sensor_sdm120_configuration_request(1,SENSOR_SDM120_BAUD_RATE);
|
||||
//sensor_sdm120_configuration_set(1,SENSOR_SDM120_METER_ID,2);
|
||||
//sensor_sdm120_configuration_set(2,SENSOR_SDM120_BAUD_RATE,2);
|
||||
|
||||
//setup ESP8266 WiFi SoC
|
||||
printf("setup ESP8266 WiFi SoC: ");
|
||||
radio_esp8266_setup();
|
||||
printf("OK\n");
|
||||
|
||||
// main loop
|
||||
printf("command input: ready\n");
|
||||
bool action = false; // if an action has been performed don't go to sleep
|
||||
|
@ -214,6 +227,7 @@ void main(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
while (sensor_pzem_measurement_received) { // measurement from electricity meter received
|
||||
struct sensor_pzem_measurement_t measurement = sensor_pzem_measurement_decode(); // decode measurement
|
||||
if (measurement.valid) { // only show valid measurement
|
||||
|
@ -230,15 +244,24 @@ void main(void)
|
|||
case SENSOR_PZEM_ENERGY:
|
||||
printf("energy: %lu Wh\n", measurement.value.energy);
|
||||
break;
|
||||
case SENSOR_PZEM_ADDRESS:
|
||||
printf("address set\n");
|
||||
break;
|
||||
case SENSOR_PZEM_ALARM:
|
||||
printf("alarm threshold set\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
while (sensor_sdm120_measurement_received) { // measurement from electricity meter received
|
||||
float measurement = sensor_sdm120_measurement_decode(); // decode measurement
|
||||
if (isnan(measurement)) {
|
||||
printf("error in measurement response\n");
|
||||
printf("error in response\n");
|
||||
} else if (isinf(measurement)) {
|
||||
printf("error message received\n");
|
||||
} else {
|
||||
printf("measurement: %.01f\n",measurement);
|
||||
}
|
||||
|
@ -254,7 +277,7 @@ void main(void)
|
|||
}
|
||||
while (rtc_internal_tick_flag) { // the internal RTC ticked
|
||||
rtc_internal_tick_flag = false; // reset flag
|
||||
led_toggle(); // toggle LED (good to indicate if main function is stuck
|
||||
//led_toggle(); // toggle LED (good to indicate if main function is stuck
|
||||
ticks_time = rtc_get_counter_val(); // copy time from internal RTC for processing
|
||||
action = true; // action has been performed
|
||||
if (ticks_time!=0 && (ticks_time%(24*60*60))==0) { // one day passed
|
||||
|
|
Loading…
Reference in New Issue