interrupting ntp and api communication if tcpip connection cant be established too many times. configuring PT1000_PT100 by station_config.h file

ZT19
Mateusz Lubecki 2024-09-08 13:48:06 +02:00
rodzic 9da9d12064
commit 8229c873ef
13 zmienionych plików z 154 dodań i 39 usunięć

Wyświetl plik

@ -336,6 +336,7 @@
<listOptionValue builtIn="false" value="&quot;../system/include/tiny-aes&quot;"/>
<listOptionValue builtIn="false" value="&quot;../system/include/aprs&quot;"/>
<listOptionValue builtIn="false" value="&quot;../system/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;../system/include/tm&quot;"/>
<listOptionValue builtIn="false" value="&quot;../system/include/cmsis/stm32l4xx&quot;"/>
<listOptionValue builtIn="false" value="&quot;../system/include/cmsis/stm32l4xx/device&quot;"/>
<listOptionValue builtIn="false" value="&quot;../system/include/stm32l4-hal-driver&quot;"/>

10
.vscode/settings.json vendored
Wyświetl plik

@ -20,6 +20,14 @@
"nvm_event.h": "c",
"nvm_internals.h": "c",
"main.h": "c",
"main_master_time.h": "c"
"main_master_time.h": "c",
"preprogrammed_gprs_apn_list.h": "c",
"sim800c_gprs.h": "c",
"sim800c_imsi.h": "c",
"events_gsm_gprs.h": "c",
"gsm_comm_state_handler.h": "c",
"sim800_state_t.h": "c",
"tm_stm32_rtc.h": "c",
"stm32l4xx_ll_rtc.h": "c"
}
}

Wyświetl plik

@ -14,6 +14,6 @@ void api_init(const char * api_base, const char * station_name);
void api_calculate_mac(void);
void api_send_json_status(void);
void api_send_json_measuremenets(void);
void api_send_json_event(const event_log_exposed_t * event);
uint8_t api_send_json_event(const event_log_exposed_t * event);
#endif /* API_H_ */

Wyświetl plik

@ -8,8 +8,8 @@
#ifndef SOFTWARE_VERSION_H_
#define SOFTWARE_VERSION_H_
#define SW_VER "EC00"
#define SW_DATE "19082024"
#define SW_VER "EC01"
#define SW_DATE "08092024"
#define SW_KISS_PROTO "C"
extern const char software_version_str[5];

Wyświetl plik

@ -0,0 +1,70 @@
/*
* config_data_ptsensor.h
*
* Created on: Sep 8, 2024
* Author: mateusz
*/
#ifndef STORED_CONFIGURATION_NVM_CONFIG_DATA_PTSENSOR_H_
#define STORED_CONFIGURATION_NVM_CONFIG_DATA_PTSENSOR_H_
/// ==================================================================================================
/// GLOBAL MACROS
/// ==================================================================================================
#define CONFIG_DATA_PTSENSOR_ASSEMBLE_CONFIG(sensor, resistor) ((sensor & 0x3) | ((resistor & 0x3F) << 2))
/// ==================================================================================================
/// GLOBAL DEFINITIONS
/// ==================================================================================================
#define CONFIG_DATA_PTSENSOR_RREF_430 (0u)
#define CONFIG_DATA_PTSENSOR_RREF_432 (1u)
#define CONFIG_DATA_PTSENSOR_RREF_442 (2u)
#define CONFIG_DATA_PTSENSOR_RREF_470 (3u)
#define CONFIG_DATA_PTSENSOR_RREF_499 (4u)
#define CONFIG_DATA_PTSENSOR_RREF_510 (5u)
#define CONFIG_DATA_PTSENSOR_RREF_560 (6u)
#define CONFIG_DATA_PTSENSOR_RREF_620 (7u)
#define CONFIG_DATA_PTSENSOR_RREF_680 (8u)
#define CONFIG_DATA_PTSENSOR_RREF_768 (9u)
#define CONFIG_DATA_PTSENSOR_RREF_1000 (10u)
#define CONFIG_DATA_PTSENSOR_RREF_1100 (11u)
#define CONFIG_DATA_PTSENSOR_RREF_1200 (12u)
#define CONFIG_DATA_PTSENSOR_RREF_1300 (13u)
#define CONFIG_DATA_PTSENSOR_RREF_1400 (14u)
#define CONFIG_DATA_PTSENSOR_RREF_1500 (15u)
#define CONFIG_DATA_PTSENSOR_RREF_1600 (16u)
#define CONFIG_DATA_PTSENSOR_RREF_1740 (17u)
#define CONFIG_DATA_PTSENSOR_RREF_1800 (18u)
#define CONFIG_DATA_PTSENSOR_RREF_1910 (19u)
#define CONFIG_DATA_PTSENSOR_RREF_2000 (20u)
#define CONFIG_DATA_PTSENSOR_RREF_2100 (21u)
#define CONFIG_DATA_PTSENSOR_RREF_2400 (22u)
#define CONFIG_DATA_PTSENSOR_RREF_2700 (23u)
#define CONFIG_DATA_PTSENSOR_RREF_3000 (24u)
#define CONFIG_DATA_PTSENSOR_RREF_3090 (25u)
#define CONFIG_DATA_PTSENSOR_RREF_3400 (26u)
#define CONFIG_DATA_PTSENSOR_RREF_3900 (27u)
#define CONFIG_DATA_PTSENSOR_RREF_4300 (28u)
#define CONFIG_DATA_PTSENSOR_RREF_4700 (29u)
#define CONFIG_DATA_PTSENSOR_RREF_4990 (30u)
#define CONFIG_DATA_PTSENSOR_3WIRE (3u)
#define CONFIG_DATA_PTSENSOR_4_OR_2WIRE (1u)
/// ==================================================================================================
/// GLOBAL TYPEDEFS
/// ==================================================================================================
/// ==================================================================================================
/// GLOBAL VARIABLES
/// ==================================================================================================
/// ==================================================================================================
/// GLOBAL FUNCTIONS
/// ==================================================================================================
#endif /* STORED_CONFIGURATION_NVM_CONFIG_DATA_PTSENSOR_H_ */

Wyświetl plik

@ -31,7 +31,7 @@ char api_url_buffer[URL_BUFFER_LN];
uint32_t api_buffer_idx = 0;
/**
* Value returned from http client
* Last value returned from http client
*/
uint8_t api_retval = 0xFF;
@ -175,7 +175,7 @@ void api_send_json_measuremenets(void) {
}
}
void api_send_json_event(const event_log_exposed_t * event) {
uint8_t api_send_json_event(const event_log_exposed_t * event) {
BEGIN
PRINT_STRING(api_station_name, station_name);
PRINT_32INT(event->event_master_time, event_master_time);
@ -196,6 +196,8 @@ void api_send_json_event(const event_log_exposed_t * event) {
api_retval = http_client_async_post(api_url_buffer, strlen(api_url_buffer), OUT, strlen(OUT), 0, api_callback);
}
return api_retval;
}

Wyświetl plik

@ -46,11 +46,11 @@ void gsm_comm_state_handler (uint8_t ntp_done,
{
gsm_comm_state_machine = GSM_COMM_NTP;
}
else if (ntp_done > 0 && api_log_events_remaining > 0)
else if (ntp_done > 0 && api_log_events_remaining > 0)
{
gsm_comm_state_machine = GSM_COMM_API;
}
else if (ntp_done > 0 && api_log_events_remaining == 0)
else if (ntp_done > 0 && api_log_events_remaining == 0)
{
gsm_comm_state_machine = GSM_COMM_APRSIS;
}
@ -63,4 +63,4 @@ void gsm_comm_state_handler (uint8_t ntp_done,
{
gsm_comm_state_machine = GSM_COMM_NO_GPRS;
}
}
}

Wyświetl plik

@ -2066,10 +2066,17 @@ int main(int argc, char* argv[]){
// if there are any events remaining to push to API
if (main_events_extracted_for_api_stat.zz_total > 0) {
// send current event
api_send_json_event(&main_exposed_events[main_events_extracted_for_api_stat.zz_total - 1]);
const uint8_t api_connection_result = api_send_json_event(&main_exposed_events[main_events_extracted_for_api_stat.zz_total - 1]);
// end decrement remaining number of events
main_events_extracted_for_api_stat.zz_total--;
// if TCP connection is established and data is currently sent asynchronously
if (api_connection_result == HTTP_CLIENT_OK) {
// end decrement remaining number of events
main_events_extracted_for_api_stat.zz_total--;
}
else {
// for sake of simplicity break on first connection error
main_events_extracted_for_api_stat.zz_total = 0;
}
}
}

Wyświetl plik

@ -23,7 +23,9 @@
#define NTP_PACKET_SIZE 48
#define NTP_TXTM_S_OFFSET (NTP_PACKET_SIZE - sizeof (uint32_t) * 2)
#define NTP_TXTM_S_OFFSET (NTP_PACKET_SIZE - sizeof (uint32_t) * 2)
#define NTP_MAXIMUM_ERRORS (3U)
/// ==================================================================================================
/// LOCAL DATA TYPES
@ -82,6 +84,9 @@ static LL_RTC_TimeTypeDef ntp_rtc_time;
static LL_RTC_DateTypeDef ntp_rtc_date;
//!< Counter of various kind of comm errors while trying to get date and time from NTP
static uint8_t ntp_synchro_errors_cnt = 0;
/// ==================================================================================================
/// GLOBAL VARIABLES
/// ==================================================================================================
@ -131,6 +136,13 @@ void ntp_init (srl_context_t *context, gsm_sim800_state_t *gsm_modem_state)
*/
void ntp_get_sync (void)
{
// check if too many connection errors has been detected before
if (ntp_synchro_errors_cnt > NTP_MAXIMUM_ERRORS)
{
ntp_done = 2u;
return;
}
memset (ntp_packet_buffer, 0, sizeof (ntp_packet_t));
// Initialize values needed to form NTP request
@ -204,6 +216,7 @@ void ntp_get_sync (void)
ntp_rtc_time.Seconds);
}
else {
ntp_synchro_errors_cnt++;
event_log_sync(
EVENT_ERROR,
EVENT_SRC_MAIN,
@ -214,6 +227,7 @@ void ntp_get_sync (void)
}
}
else {
ntp_synchro_errors_cnt++;
event_log_sync(
EVENT_ERROR,
EVENT_SRC_MAIN,
@ -224,6 +238,7 @@ void ntp_get_sync (void)
}
}
else {
ntp_synchro_errors_cnt++;
event_log_sync(
EVENT_ERROR,
EVENT_SRC_MAIN,

Wyświetl plik

@ -10,6 +10,8 @@
// reprogram it from the default set stored somewhere within .code section
#include <stored_configuration_nvm/config_data.h>
#include <stored_configuration_nvm/config_data_ptsensor.h>
#include "io_default_vbat_scaling.h"
#include "station_config.h"
@ -78,7 +80,11 @@ const config_data_mode_t __attribute__((section(".config_section_default.mode"))
.wx_umb = 0,
#endif
.wx_pt_sensor = 0x71, // TODO:
#if ((!defined _PT_SENSOR_REFERENCE_RES) && (!defined _PT_SENSOR_TYPE))
.wx_pt_sensor = 0x71, // TODO: index 28 (4k1 reference resistor), 4-wire sensor
#else
.wx_pt_sensor = CONFIG_DATA_PTSENSOR_ASSEMBLE_CONFIG(_PT_SENSOR_TYPE, _PT_SENSOR_REFERENCE_RES),
#endif
#ifdef _DUST_SDS011_SERIAL
.wx_dust_sensor = WX_DUST_SDS011_SERIAL,

Wyświetl plik

@ -26,6 +26,7 @@
#define HTTP_CLIENT_RET_UNITIALIZED 1
#define HTTP_CLIENT_RET_TCPIP_BSY 2
#define HTTP_CLIENT_RET_WRONG_URL 3
#define HTTP_CLIENT_RET_TCPIP_ERROR 4
#define HTTP_CLIENT_MAX_CONNECTION_ERRORS 8

Wyświetl plik

@ -34,34 +34,34 @@ typedef enum max31865_pool_state_t {
static const float max31865_rref_lookup_table[32] =
{
430.0f,
432.0f,
442.0f,
470.0f,
499.0f,
510.0f,
560.0f,
620.0f,
680.0f,
430.0f, // index 0
432.0f, // index 1
442.0f, // index 2
470.0f, // index 3
499.0f, // index 4
510.0f, // index 5
560.0f, // index 6
620.0f, // index 7
680.0f, // index 8
768.0f, // index 9
1000.0f,
1100.0f,
1200.0f,
1300.0f,
1400.0f,
1500.0f,
1600.0f,
1740.0f,
1800.0f,
1000.0f, // index 10
1100.0f, // index 11
1200.0f, // index 12
1300.0f, // index 13
1400.0f, // index 14
1500.0f, // index 15
1600.0f, // index 16
1740.0f, // index 17
1800.0f, // index 18
1910.0f, // index 19
2000.0f, // index 20
2100.0f,
2400.0f,
2700.0f,
3000.0f,
3090.0f,
3400.0f,
3900.0f,
2100.0f, // index 21
2400.0f, // index 22
2700.0f, // index 23
3000.0f, // index 24
3090.0f, // index 25
3400.0f, // index 26
3900.0f, // index 27
4300.0f, // index 28
4700.0f, // index 29
4990.0f, // index 30

Wyświetl plik

@ -394,6 +394,11 @@ uint8_t http_client_async_post(char * url, uint8_t url_ln, char * data_to_post,
http_client_connection_errors++;
}
// check if TCPIP communication was successfull
if (connect_result != SIM800_OK) {
out = HTTP_CLIENT_RET_TCPIP_ERROR;
}
return out;
}