Skip to content

Commit

Permalink
LedClock version 0.1.0 done
Browse files Browse the repository at this point in the history
  • Loading branch information
luk6xff committed Nov 27, 2020
1 parent ad54e8e commit ce27426
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 27 deletions.
3 changes: 1 addition & 2 deletions esp32-app/lib/LORA/platform/stm32cube/hal/lora-cube-hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ bool lora_cube_hal_init(lora *const dev, lora_cube_hal *const cube_dev)
//-----------------------------------------------------------------------------
void lora_cube_hal_deinit(lora *const dev)
{
// IO
lora_io_deinit(dev);
lora_end(dev);
}

//-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion esp32-app/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ build_flags =
;-DCONFIG_INT_WDT=0

; Upload port
upload_port = /dev/ttyUSB1
upload_port = /dev/ttyUSB0
;upload_port = COM38

; Extra scripts
Expand Down
8 changes: 2 additions & 6 deletions esp32-app/src/App/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@
#include "Weather/weather_settings.h"
#include "Radio/radio_settings.h"
#include "Display/display_settings.h"
#include "app_settings.h"
#include "rtos_common.h"



// Define the version number, also used for webserver as Last-Modified header and to check version for update.
#define APP_VERSION "0.0.1"
#include "app_settings.h"
#include "app_vars.h"

// LedClock App can be updated (OTA) to the latest version from a remote server.
#define APP_UPDATEHOST "github.com" // Host for software updates
Expand Down
2 changes: 1 addition & 1 deletion esp32-app/src/App/app_vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
*/

// Define the app version number
#define APP_VERSION "0.0.1"
#define APP_VERSION "0.1.0"

#define APP_DATE_LAST_MODIFIED "Tue, 24 Nov 2020 01:44:45 GMT"
1 change: 0 additions & 1 deletion esp32-app/src/Radio/radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define __RADIO_H__

#include "radio_settings.h"
//#include "../SX1278/platform/arduino/sx1278-arduino.h"
#include "../LORA/platform/arduino/lora-arduino.h"

/**
Expand Down
4 changes: 2 additions & 2 deletions esp32-app/src/Radio/radio_sensor_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ bool RadioSensorTask::pushRadioSensorMsg(const RadioSensorData& data)
String msg(tr(M_SENSOR_NAME) + col + spc + \
tr(M_SENSOR_TEMP) + col + String(data.temperature) + tr(M_COMMON_DEG_CELS) + com + spc + \
tr(M_SENSOR_PRESS) + col + String(uint32_t(data.pressure/100)) + tr(M_COMMON_PRESSURE_HPA) + com + spc + \
tr(M_SENSOR_HUMID) + col + String(uint8_t(data.humidity)) + tr(M_COMMON_PERCENT) + com + spc + \
tr(M_SENSOR_VBATT) + col + String(float(data.vbatt/1000.f)) + tr(M_COMMON_VOLTAGE));
tr(M_SENSOR_HUMID) + col + String(uint8_t(data.humidity)) + tr(M_COMMON_PERCENT));// + com + spc + \
//tr(M_SENSOR_VBATT) + col + String(float(data.vbatt/1000.f)) + tr(M_COMMON_VOLTAGE));

return AppSh.putDisplayMsg(msg.c_str(), msg.length());
}
Expand Down
37 changes: 30 additions & 7 deletions sensor-app/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ uint8_t PWR_PVDGetLevel(void)
// Last measured values
static float temperature, pressure, humidity;

// Last measured values
const uint8_t radio_health_check_state = 4;
static uint8_t radio_health_check_state_cnt = 0;

// Msg frame
static radio_msg_sensor_frame msgf =
{
Expand Down Expand Up @@ -149,9 +153,12 @@ int main(void)
/* USER CODE BEGIN 2 */
dbg("LUK6");

// Read current config from eprom
app_settings_init();
radio_init();
// Enable sensor
sensor_init();
// Enable radio
radio_init();
/* USER CODE END 2 */

/* Infinite loop */
Expand All @@ -170,6 +177,9 @@ int main(void)
{
sprintf(dbg_buf, "M_LWP_EXIT:%d", HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR2));
dbg(dbg_buf);
// Enable sensor pin
HAL_GPIO_WritePin(SENSOR_VDD_GPIO_Port, SENSOR_VDD_Pin, GPIO_PIN_SET);
HAL_Delay(100);
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR2, 0);
}

Expand All @@ -189,22 +199,38 @@ int main(void)
msgf.temperature = temperature;
msgf.pressure = pressure;
msgf.humidity = humidity;
//PWR_PVDCmd(ENABLE);
msgf.vbatt = 3300;//adc_read_vbatt();

/* Send result data */
radio_send(&msgf);

/* Refresh watchdog, no more than 2[s] must expire before next refresh */
HAL_WWDG_Refresh(&hwwdg);
uint8_t rxMsgWaitCntSecs = 10; // 5 seconds
while (rxMsgWaitCntSecs--)
uint8_t rx_msg_wait_cnt_secs = 5; // 5 seconds
while (rx_msg_wait_cnt_secs--)
{
/* Wait 1 second for incoming data from ledclock */
HAL_Delay(1000);
/* Refresh watchdog, no more than 2[s] must expire before next refresh */
HAL_WWDG_Refresh(&hwwdg);
}

// Check if any data from ledclock came
if (!radio_was_data_received())
{
radio_health_check_state_cnt++;
}
else
{
radio_health_check_state_cnt = 0;
radio_data_received_clear();
}

// If any problem with radio exists, restrat it
if (radio_health_check_state_cnt >= radio_health_check_state)
{
radio_restart();
}
}
/* USER CODE END 3 */
}
Expand Down Expand Up @@ -620,7 +646,6 @@ static void enter_low_power_mode()

/* Put radio into sleep mode */
radio_sleep();
//HAL_GPIO_WritePin(SX1278_RESET_GPIO_Port, SX1278_RESET_Pin, GPIO_PIN_SET);

/* Disable sensor */
HAL_GPIO_WritePin(SENSOR_VDD_GPIO_Port, SENSOR_VDD_Pin, GPIO_PIN_RESET);
Expand Down Expand Up @@ -669,8 +694,6 @@ static void enter_low_power_mode()
/* Enable SysTick. */
//HAL_ResumeTick();
//HAL_GPIO_WritePin(SX1278_RESET_GPIO_Port, SX1278_RESET_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(SENSOR_VDD_GPIO_Port, SENSOR_VDD_Pin, GPIO_PIN_SET);
HAL_Delay(100);
dbg("M_LPM_RUN");
}

Expand Down
52 changes: 45 additions & 7 deletions sensor-app/Core/Src/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ static lora_cube_hal cube_hal_dev =

static lora dev;

static volatile uint8_t radio_data_received = false;

//-----------------------------------------------------------------------------
void radio_init()
{
Expand All @@ -53,8 +55,8 @@ void radio_init()
lora_delay_ms(1000);
}
lora_on_receive(&dev, on_rx_done);
// Switch into idle mode
lora_idle(&dev);
// Switch sleep idle mode
lora_sleep(&dev);
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -88,6 +90,41 @@ void radio_sleep()
lora_sleep(&dev);
}

//-----------------------------------------------------------------------------
void radio_restart()
{
// Deinitilaize radio
lora_cube_hal_deinit(&dev);
lora_delay_ms(100);

// Set dev
dev.frequency = 433E6;
dev.on_receive = NULL;
dev.on_tx_done = NULL;

while (!lora_cube_hal_init(&dev, &cube_hal_dev))
{
dbg("R_RDN");
lora_delay_ms(1000);
}

lora_on_receive(&dev, on_rx_done);
// Switch into sleep mode
lora_sleep(&dev);
}

//-----------------------------------------------------------------------------
uint8_t radio_was_data_received()
{
return radio_data_received;
}

//-----------------------------------------------------------------------------
void radio_data_received_clear()
{
radio_data_received = false;
}

//-----------------------------------------------------------------------------
uint16_t radio_msg_frame_checksum(const uint8_t *data, const uint8_t data_len)
{
Expand Down Expand Up @@ -128,10 +165,10 @@ static void on_rx_done(void *ctx, int packet_size)
}

// Read packet header bytes:
hdr.receiver_id = lora_read(dev); // recipient address
hdr.sender_id = lora_read(dev); // sender address
hdr.msg_id = lora_read(dev); // incoming msg ID
hdr.payload_len = lora_read(dev); // incoming msg length
hdr.receiver_id = lora_read(dev); // recipient address
hdr.sender_id = lora_read(dev); // sender address
hdr.msg_id = lora_read(dev); // incoming msg ID
hdr.payload_len = lora_read(dev); // incoming msg length

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

parse_incoming_msg_clock(p, hdr.payload_len);

// Set global flag
radio_data_received = true;
err:
radio_sleep();
}
Expand Down
6 changes: 6 additions & 0 deletions sensor-app/Core/Src/radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,10 @@ void radio_send(radio_msg_sensor_frame *msgf);

void radio_sleep();

void radio_restart();

uint8_t radio_was_data_received();

void radio_data_received_clear();

#endif /* RADIO_H_ */

0 comments on commit ce27426

Please sign in to comment.