Skip to content

Commit ce27426

Browse files
committed
LedClock version 0.1.0 done
1 parent ad54e8e commit ce27426

9 files changed

Lines changed: 88 additions & 27 deletions

File tree

esp32-app/lib/LORA/platform/stm32cube/hal/lora-cube-hal.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ bool lora_cube_hal_init(lora *const dev, lora_cube_hal *const cube_dev)
1919
//-----------------------------------------------------------------------------
2020
void lora_cube_hal_deinit(lora *const dev)
2121
{
22-
// IO
23-
lora_io_deinit(dev);
22+
lora_end(dev);
2423
}
2524

2625
//-----------------------------------------------------------------------------

esp32-app/platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ build_flags =
2222
;-DCONFIG_INT_WDT=0
2323

2424
; Upload port
25-
upload_port = /dev/ttyUSB1
25+
upload_port = /dev/ttyUSB0
2626
;upload_port = COM38
2727

2828
; Extra scripts

esp32-app/src/App/app_config.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@
1212
#include "Weather/weather_settings.h"
1313
#include "Radio/radio_settings.h"
1414
#include "Display/display_settings.h"
15-
#include "app_settings.h"
1615
#include "rtos_common.h"
17-
18-
19-
20-
// Define the version number, also used for webserver as Last-Modified header and to check version for update.
21-
#define APP_VERSION "0.0.1"
16+
#include "app_settings.h"
17+
#include "app_vars.h"
2218

2319
// LedClock App can be updated (OTA) to the latest version from a remote server.
2420
#define APP_UPDATEHOST "github.com" // Host for software updates

esp32-app/src/App/app_vars.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
*/
88

99
// Define the app version number
10-
#define APP_VERSION "0.0.1"
10+
#define APP_VERSION "0.1.0"
1111

1212
#define APP_DATE_LAST_MODIFIED "Tue, 24 Nov 2020 01:44:45 GMT"

esp32-app/src/Radio/radio.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define __RADIO_H__
33

44
#include "radio_settings.h"
5-
//#include "../SX1278/platform/arduino/sx1278-arduino.h"
65
#include "../LORA/platform/arduino/lora-arduino.h"
76

87
/**

esp32-app/src/Radio/radio_sensor_task.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ bool RadioSensorTask::pushRadioSensorMsg(const RadioSensorData& data)
100100
String msg(tr(M_SENSOR_NAME) + col + spc + \
101101
tr(M_SENSOR_TEMP) + col + String(data.temperature) + tr(M_COMMON_DEG_CELS) + com + spc + \
102102
tr(M_SENSOR_PRESS) + col + String(uint32_t(data.pressure/100)) + tr(M_COMMON_PRESSURE_HPA) + com + spc + \
103-
tr(M_SENSOR_HUMID) + col + String(uint8_t(data.humidity)) + tr(M_COMMON_PERCENT) + com + spc + \
104-
tr(M_SENSOR_VBATT) + col + String(float(data.vbatt/1000.f)) + tr(M_COMMON_VOLTAGE));
103+
tr(M_SENSOR_HUMID) + col + String(uint8_t(data.humidity)) + tr(M_COMMON_PERCENT));// + com + spc + \
104+
//tr(M_SENSOR_VBATT) + col + String(float(data.vbatt/1000.f)) + tr(M_COMMON_VOLTAGE));
105105

106106
return AppSh.putDisplayMsg(msg.c_str(), msg.length());
107107
}

sensor-app/Core/Src/main.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ uint8_t PWR_PVDGetLevel(void)
100100
// Last measured values
101101
static float temperature, pressure, humidity;
102102

103+
// Last measured values
104+
const uint8_t radio_health_check_state = 4;
105+
static uint8_t radio_health_check_state_cnt = 0;
106+
103107
// Msg frame
104108
static radio_msg_sensor_frame msgf =
105109
{
@@ -149,9 +153,12 @@ int main(void)
149153
/* USER CODE BEGIN 2 */
150154
dbg("LUK6");
151155

156+
// Read current config from eprom
152157
app_settings_init();
153-
radio_init();
158+
// Enable sensor
154159
sensor_init();
160+
// Enable radio
161+
radio_init();
155162
/* USER CODE END 2 */
156163

157164
/* Infinite loop */
@@ -170,6 +177,9 @@ int main(void)
170177
{
171178
sprintf(dbg_buf, "M_LWP_EXIT:%d", HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR2));
172179
dbg(dbg_buf);
180+
// Enable sensor pin
181+
HAL_GPIO_WritePin(SENSOR_VDD_GPIO_Port, SENSOR_VDD_Pin, GPIO_PIN_SET);
182+
HAL_Delay(100);
173183
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR2, 0);
174184
}
175185

@@ -189,22 +199,38 @@ int main(void)
189199
msgf.temperature = temperature;
190200
msgf.pressure = pressure;
191201
msgf.humidity = humidity;
192-
//PWR_PVDCmd(ENABLE);
193202
msgf.vbatt = 3300;//adc_read_vbatt();
194203

195204
/* Send result data */
196205
radio_send(&msgf);
197206

198207
/* Refresh watchdog, no more than 2[s] must expire before next refresh */
199208
HAL_WWDG_Refresh(&hwwdg);
200-
uint8_t rxMsgWaitCntSecs = 10; // 5 seconds
201-
while (rxMsgWaitCntSecs--)
209+
uint8_t rx_msg_wait_cnt_secs = 5; // 5 seconds
210+
while (rx_msg_wait_cnt_secs--)
202211
{
203212
/* Wait 1 second for incoming data from ledclock */
204213
HAL_Delay(1000);
205214
/* Refresh watchdog, no more than 2[s] must expire before next refresh */
206215
HAL_WWDG_Refresh(&hwwdg);
207216
}
217+
218+
// Check if any data from ledclock came
219+
if (!radio_was_data_received())
220+
{
221+
radio_health_check_state_cnt++;
222+
}
223+
else
224+
{
225+
radio_health_check_state_cnt = 0;
226+
radio_data_received_clear();
227+
}
228+
229+
// If any problem with radio exists, restrat it
230+
if (radio_health_check_state_cnt >= radio_health_check_state)
231+
{
232+
radio_restart();
233+
}
208234
}
209235
/* USER CODE END 3 */
210236
}
@@ -620,7 +646,6 @@ static void enter_low_power_mode()
620646

621647
/* Put radio into sleep mode */
622648
radio_sleep();
623-
//HAL_GPIO_WritePin(SX1278_RESET_GPIO_Port, SX1278_RESET_Pin, GPIO_PIN_SET);
624649

625650
/* Disable sensor */
626651
HAL_GPIO_WritePin(SENSOR_VDD_GPIO_Port, SENSOR_VDD_Pin, GPIO_PIN_RESET);
@@ -669,8 +694,6 @@ static void enter_low_power_mode()
669694
/* Enable SysTick. */
670695
//HAL_ResumeTick();
671696
//HAL_GPIO_WritePin(SX1278_RESET_GPIO_Port, SX1278_RESET_Pin, GPIO_PIN_RESET);
672-
HAL_GPIO_WritePin(SENSOR_VDD_GPIO_Port, SENSOR_VDD_Pin, GPIO_PIN_SET);
673-
HAL_Delay(100);
674697
dbg("M_LPM_RUN");
675698
}
676699

sensor-app/Core/Src/radio.c

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ static lora_cube_hal cube_hal_dev =
3939

4040
static lora dev;
4141

42+
static volatile uint8_t radio_data_received = false;
43+
4244
//-----------------------------------------------------------------------------
4345
void radio_init()
4446
{
@@ -53,8 +55,8 @@ void radio_init()
5355
lora_delay_ms(1000);
5456
}
5557
lora_on_receive(&dev, on_rx_done);
56-
// Switch into idle mode
57-
lora_idle(&dev);
58+
// Switch sleep idle mode
59+
lora_sleep(&dev);
5860
}
5961

6062
//-----------------------------------------------------------------------------
@@ -88,6 +90,41 @@ void radio_sleep()
8890
lora_sleep(&dev);
8991
}
9092

93+
//-----------------------------------------------------------------------------
94+
void radio_restart()
95+
{
96+
// Deinitilaize radio
97+
lora_cube_hal_deinit(&dev);
98+
lora_delay_ms(100);
99+
100+
// Set dev
101+
dev.frequency = 433E6;
102+
dev.on_receive = NULL;
103+
dev.on_tx_done = NULL;
104+
105+
while (!lora_cube_hal_init(&dev, &cube_hal_dev))
106+
{
107+
dbg("R_RDN");
108+
lora_delay_ms(1000);
109+
}
110+
111+
lora_on_receive(&dev, on_rx_done);
112+
// Switch into sleep mode
113+
lora_sleep(&dev);
114+
}
115+
116+
//-----------------------------------------------------------------------------
117+
uint8_t radio_was_data_received()
118+
{
119+
return radio_data_received;
120+
}
121+
122+
//-----------------------------------------------------------------------------
123+
void radio_data_received_clear()
124+
{
125+
radio_data_received = false;
126+
}
127+
91128
//-----------------------------------------------------------------------------
92129
uint16_t radio_msg_frame_checksum(const uint8_t *data, const uint8_t data_len)
93130
{
@@ -128,10 +165,10 @@ static void on_rx_done(void *ctx, int packet_size)
128165
}
129166

130167
// Read packet header bytes:
131-
hdr.receiver_id = lora_read(dev); // recipient address
132-
hdr.sender_id = lora_read(dev); // sender address
133-
hdr.msg_id = lora_read(dev); // incoming msg ID
134-
hdr.payload_len = lora_read(dev); // incoming msg length
168+
hdr.receiver_id = lora_read(dev); // recipient address
169+
hdr.sender_id = lora_read(dev); // sender address
170+
hdr.msg_id = lora_read(dev); // incoming msg ID
171+
hdr.payload_len = lora_read(dev); // incoming msg length
135172

136173
// If the recipient isn't this device or broadcast,
137174
if (hdr.receiver_id != LORA_RADIO_SENSOR_ID && hdr.receiver_id != 0xFF)
@@ -152,7 +189,8 @@ static void on_rx_done(void *ctx, int packet_size)
152189
}
153190

154191
parse_incoming_msg_clock(p, hdr.payload_len);
155-
192+
// Set global flag
193+
radio_data_received = true;
156194
err:
157195
radio_sleep();
158196
}

sensor-app/Core/Src/radio.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,10 @@ void radio_send(radio_msg_sensor_frame *msgf);
6666

6767
void radio_sleep();
6868

69+
void radio_restart();
70+
71+
uint8_t radio_was_data_received();
72+
73+
void radio_data_received_clear();
74+
6975
#endif /* RADIO_H_ */

0 commit comments

Comments
 (0)