Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions firmware/main/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
Expand Down
8 changes: 5 additions & 3 deletions firmware/main/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_wifi.h"
Expand Down Expand Up @@ -242,11 +243,12 @@ static int nvs_dump(int argc, char **argv)
}

// Example of listing all the key-value pairs of any type under specified partition and namespace
nvs_iterator_t it = nvs_entry_find("nvs", nvs_dump_args.namespace->sval[0], NVS_TYPE_ANY);
nvs_iterator_t it;
nvs_entry_find("nvs", nvs_dump_args.namespace->sval[0], NVS_TYPE_ANY, &it);
while (it != NULL) {
nvs_entry_info_t info;
nvs_entry_info(it, &info);
it = nvs_entry_next(it);
nvs_entry_next(&it);
printf("%s.%s=", info.namespace_name, info.key);

switch(info.type) {
Expand Down Expand Up @@ -416,7 +418,7 @@ static int fetch_acl(int argc, char **argv)

static int system_free(int argc, char **argv)
{
printf("\n\nFree heap memory: %d bytes\n", esp_get_free_heap_size());
printf("\n\nFree heap memory: %ld bytes\n", esp_get_free_heap_size());
return ESP_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion firmware/main/main_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void main_task(void *pvParameters)
beep_queue(_beep_invalid);

char tagstr[12];
snprintf(tagstr, sizeof(tagstr), "%10.10u", active_member_record.tag);
snprintf(tagstr, sizeof(tagstr), "%10.10lu", active_member_record.tag);
net_cmd_queue_access_error("unknown rfid tag", tagstr);

xTimerChangePeriod(timer, 8000 / portTICK_PERIOD_MS, 0);
Expand Down
3 changes: 3 additions & 0 deletions firmware/main/net/https.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ static esp_err_t http_get_file_event_handler(esp_http_client_event_t *evt)
case HTTP_EVENT_DISCONNECTED:
ESP_LOGD(TAG, "HTTP_EVENT_DISCONNECTED");
break;
case HTTP_EVENT_REDIRECT:
ESP_LOGD(TAG, "HTTP_EVENT_REDIRECT");
break;
}
return ESP_OK;
}
Expand Down
6 changes: 3 additions & 3 deletions firmware/main/net/net_certs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
#ifndef _NET_CERTS_H
#define _NET_CERTS_H

char* g_client_cert;
char* g_client_key;
char* g_ca_cert;
extern char* g_client_cert;
extern char* g_client_key;
extern char* g_ca_cert;

esp_err_t net_certs_init();

Expand Down
1 change: 1 addition & 0 deletions firmware/main/net/net_https.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
Expand Down
30 changes: 20 additions & 10 deletions firmware/main/net/net_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@
#include "lwip/ip4_addr.h"

#include "mbedtls/platform.h"
#include "mbedtls/net.h"
#include "mbedtls/net_sockets.h"
#include "mbedtls/debug.h"
#include "mbedtls/ssl.h"
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/error.h"
#include "mbedtls/certs.h"
#include "mbedtls/base64.h"
#include "esp_ota_ops.h"

Expand Down Expand Up @@ -366,8 +365,10 @@ void net_mqtt_send_ota_status(ota_status_t status, int progress)
}


static esp_err_t net_mqtt_event_handler(esp_mqtt_event_handle_t event)
//static esp_err_t net_mqtt_event_handler(esp_mqtt_event_handle_t event)
static void net_mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
{
esp_mqtt_event_handle_t event = event_data;
esp_mqtt_client_handle_t client = event->client;
int msg_id;
// your_context_t *context = event->context;
Expand Down Expand Up @@ -421,7 +422,7 @@ static esp_err_t net_mqtt_event_handler(esp_mqtt_event_handle_t event)
ESP_LOGD(TAG, "Other event id:%d", event->event_id);
break;
}
return ESP_OK;
return;
}


Expand All @@ -438,22 +439,31 @@ int net_mqtt_init(void)
esp_log_level_set("OUTBOX", ESP_LOG_WARN);

esp_mqtt_client_config_t mqtt_cfg = {
.event_handle = net_mqtt_event_handler,
.client_cert_pem = g_client_cert,
.client_key_pem = g_client_key,
.cert_pem = g_ca_cert,
.skip_cert_common_name_check = true,
.credentials = {
.authentication = {
.certificate = g_client_cert,
.key = g_client_key
}
},
.broker = {
.verification = {
.certificate = g_ca_cert,
.skip_cert_common_name_check = true
}
}
};

char *conf_mqtt_broker;
config_get_string("mqtt_broker", &conf_mqtt_broker, "mqtts://my-mqtt-server.org:1883");

ESP_LOGI(TAG, "MQTT broker is %s", conf_mqtt_broker);

mqtt_cfg.uri = conf_mqtt_broker;
mqtt_cfg.broker.address.uri = conf_mqtt_broker;

s_mqtt_client = esp_mqtt_client_init(&mqtt_cfg);

esp_mqtt_client_register_event(s_mqtt_client, ESP_EVENT_ANY_ID, net_mqtt_event_handler, NULL);

esp_log_level_set(TAG, ESP_LOG_INFO);

free(conf_mqtt_broker);
Expand Down
10 changes: 8 additions & 2 deletions firmware/main/net/net_ota.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,29 @@ esp_err_t net_ota_http_event_handler(esp_http_client_event_t *evt)
case HTTP_EVENT_DISCONNECTED:
ESP_LOGD(TAG, "HTTP_EVENT_DISCONNECTED");
break;
case HTTP_EVENT_REDIRECT:
ESP_LOGD(TAG, "HTTP_EVENT_REDIRECT");
break;
}
return ESP_OK;
}


void net_ota_update(void)
{
esp_http_client_config_t config = {
esp_http_client_config_t http_config = {
.cert_pem = g_ca_cert,
.skip_cert_common_name_check = true,
.keep_alive_enable = true,
.event_handler = net_ota_http_event_handler,
};
esp_https_ota_config_t config = {
.http_config = &http_config
};

char *conf_ota_url;
config_get_string("ota_url", &conf_ota_url, "https://my-server.org/ota.bin");
config.url = conf_ota_url;
http_config.url = conf_ota_url;

ESP_LOGI(TAG, "Starting OTA update from %s", conf_ota_url);

Expand Down
14 changes: 7 additions & 7 deletions firmware/main/net/net_sntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ void net_sntp_init(void)
esp_log_level_set(TAG, ESP_LOG_DEBUG);
ESP_LOGI(TAG, "Initializing SNTP...");

sntp_setoperatingmode(SNTP_OPMODE_POLL);
esp_sntp_setoperatingmode(SNTP_OPMODE_POLL);

char *conf_ntp_server;
config_get_string("ntp_server", &conf_ntp_server, "pool.ntp.org");
strncpy(ntp_server, conf_ntp_server, sizeof(ntp_server));
free(conf_ntp_server);
ESP_LOGI(TAG, "ntp server is %s", ntp_server);

sntp_setservername(0, ntp_server);
esp_sntp_setservername(0, ntp_server);

sntp_set_time_sync_notification_cb(net_sntp_sync_cb);
sntp_set_sync_mode(SNTP_SYNC_MODE_SMOOTH);
esp_sntp_set_time_sync_notification_cb(net_sntp_sync_cb);
esp_sntp_set_sync_mode(SNTP_SYNC_MODE_SMOOTH);

sntp_set_sync_interval(1800000);
esp_sntp_set_sync_interval(1800000);

ESP_LOGI(TAG, "ntp update interval is %d msec", sntp_get_sync_interval());
sntp_init();
esp_sntp_init();

s_initialized = true;
}
Expand All @@ -78,6 +78,6 @@ void net_sntp_init(void)
void net_sntp_stop(void)
{
ESP_LOGI(TAG, "Stopping SNTP...");
sntp_stop();
esp_sntp_stop();
s_initialized = false;
}
6 changes: 3 additions & 3 deletions firmware/main/net/net_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_mac.h"
#include "esp_wifi.h"
#include "esp_wifi_default.h"
#include "esp_event.h"
Expand All @@ -59,13 +60,12 @@
#include "lwip/ip4_addr.h"

#include "mbedtls/platform.h"
#include "mbedtls/net.h"
#include "mbedtls/net_sockets.h"
#include "mbedtls/debug.h"
#include "mbedtls/ssl.h"
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/error.h"
#include "mbedtls/certs.h"
#include "mbedtls/base64.h"

#include "display_task.h"
Expand All @@ -87,7 +87,7 @@ void net_timer(TimerHandle_t xTimer);


static int s_active_interfaces = 0;
static xSemaphoreHandle s_semph_get_ip_addrs;
static SemaphoreHandle_t s_semph_get_ip_addrs;
static esp_netif_t *s_example_esp_netif = NULL;


Expand Down
6 changes: 3 additions & 3 deletions firmware/main/rfid_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ uint8_t rfid_lookup(uint32_t tag, member_record_t *member)
char line[LINE_SIZE];
char *conf_acl_filename;

snprintf(tag_ascii, sizeof(tag_ascii), "%10.10u", tag);
snprintf(tag_ascii, sizeof(tag_ascii), "%10.10lu", tag);
rfid_hash_sha224(tag_ascii, strlen(tag_ascii), tag_sha224, sizeof(tag_sha224));

ESP_LOGD(TAG, "RFID tag: %10.10u", tag);
Expand Down Expand Up @@ -217,7 +217,7 @@ void rfid_task(void *pvParameters)
while(1) {
esp_task_wdt_reset();

int len = uart_read_bytes(uart_num, rxbuf, SER_BUF_SIZE, 20 / portTICK_RATE_MS);
int len = uart_read_bytes(uart_num, rxbuf, SER_BUF_SIZE, 20 / portTICK_PERIOD_MS);

if (len==10) {
uint8_t checksum_calc = 0;
Expand All @@ -228,7 +228,7 @@ void rfid_task(void *pvParameters)

char s[80];
ESP_LOGD(TAG, "Good RFID tag checksum, bytes follow:");
snprintf(s, sizeof(s), "%10.10u %2.2X %2.2X %2.2X %2.2X [%2.2X == %2.2X]", tag, rxbuf[4], rxbuf[5], rxbuf[6], rxbuf[7], rxbuf[8], checksum_calc);
snprintf(s, sizeof(s), "%10.10lu %2.2X %2.2X %2.2X %2.2X [%2.2X == %2.2X]", tag, rxbuf[4], rxbuf[5], rxbuf[6], rxbuf[7], rxbuf[8], checksum_calc);
ESP_LOGD(TAG, "%s", s);

if (tag != 0) {
Expand Down
6 changes: 6 additions & 0 deletions firmware/main/system/gpio_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@


#ifdef HARDWARE_REV1

#define GPIO_SEL_4 (BIT(4))
#define GPIO_SEL_27 (BIT(27))
#define GPIO_SEL_32 ((uint64_t)(((uint64_t)1)<<32))
#define GPIO_SEL_33 ((uint64_t)(((uint64_t)1)<<33))

#define GPIO_PIN_IO0 (0)
#define GPIO_PIN_TXD0 (1)
#define GPIO_PIN_SD_DAT0 (2)
Expand Down
4 changes: 2 additions & 2 deletions firmware/main/system/i2c_periph.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ esp_err_t i2c_write(uint8_t addr, uint8_t* data_wr, size_t size)
i2c_master_write_byte(link, ( addr << 1 ) | WRITE_BIT, ACK_CHECK_EN);
i2c_master_write(link, data_wr, size, ACK_CHECK_EN);
i2c_master_stop(link);
esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_NUM, link, 1000 / portTICK_RATE_MS);
esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_NUM, link, 1000 / portTICK_PERIOD_MS);
i2c_cmd_link_delete(link);
return ret;
}
Expand All @@ -99,7 +99,7 @@ esp_err_t i2c_read(uint8_t addr, uint8_t reg, uint8_t* data_rd, size_t size)
i2c_master_read_byte(link, data_rd + size - 1, NACK_VAL);

i2c_master_stop(link);
esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_NUM, link, 1000 / portTICK_RATE_MS);
esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_NUM, link, 1000 / portTICK_PERIOD_MS);
i2c_cmd_link_delete(link);
return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions firmware/main/ui/display_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ void display_init()
void display_task(void *pvParameters)
#ifdef DISPLAY_ENABLED
{
portTickType init_tick = xTaskGetTickCount();
portTickType last_heartbeat_tick = init_tick;
TickType_t init_tick = xTaskGetTickCount();
TickType_t last_heartbeat_tick = init_tick;
int button=0, last_button=0;

lv_obj_t *scr_splash = ui_splash_create();
Expand Down Expand Up @@ -369,7 +369,7 @@ void display_task(void *pvParameters)
}
}

portTickType now = xTaskGetTickCount();
TickType_t now = xTaskGetTickCount();


if (now - last_heartbeat_tick >= (1000/portTICK_PERIOD_MS)) {
Expand Down
2 changes: 1 addition & 1 deletion firmware/main/ui/esp_lcd_panel_st7735.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ esp_err_t esp_lcd_new_panel_st7735(const esp_lcd_panel_io_handle_t io, const esp
st7735->base.set_gap = panel_st7735_set_gap;
st7735->base.mirror = panel_st7735_mirror;
st7735->base.swap_xy = panel_st7735_swap_xy;
st7735->base.disp_off = panel_st7735_disp_off;
st7735->base.disp_on_off = panel_st7735_disp_off;
*ret_panel = &(st7735->base);
ESP_LOGD(TAG, "new st7735 panel @%p", st7735);

Expand Down
Loading