Hi everyone,
I am working on project that which will connect to BLE devices we have made and send data to Broker on via MQTT and also will require to set wifi setting and restore it if reset or restarted.
I am right now working with 3 example codes of ESP32 (this is my first time working with IDF, I previous have worked with ESP8266 with arduino)
1) BLUFI example
2) MQTT example(https://github.com/tuanpmt/esp32-mqtt)
3) GATT client example.
Right now I have understood BLUFI code somewhat. It sets wifi setting in function example_event_callback() at ESP_BLUFI_EVENT_RECV_STA_SSID and ESP_BLUFI_EVENT_RECV_STA_PASSWD. And MQTT example sets it in user_config.sample.h which we have to hardcode it. I want to replace that and also store it to flash to load it if Device restarts.
Can anyone please guide me. I have currently seperated all BLE function,variables and structs in seperate file and same with wifi so as to easily manage things. It compiles well without any changes.
BLE GATT CLIENT MQTT gateway.
-
- Posts: 60
- Joined: Mon Jun 26, 2017 5:36 am
Re: BLE GATT CLIENT MQTT gateway.
I have made some psudo code in esp32-mqtt to set wifi setting if they are available in storage or if not available start BLUFI.
here it is, can some one confirm its ok ?
I will other functions later.
here it is, can some one confirm its ok ?
I will other functions later.
Code: Select all
void app_main()
{
INFO("[APP] Startup..\n");
INFO("[APP] Free memory: %d bytes\n", system_get_free_heap_size());
INFO("[APP] SDK version: %s, Build time: %s\n", system_get_sdk_version(), BUID_TIME);
#ifdef CPU_FREQ_160MHZ
INFO("[APP] Setup CPU run as 160MHz\n");
SET_PERI_REG_BITS(RTC_CLK_CONF, RTC_CNTL_SOC_CLK_SEL, 0x1, RTC_CNTL_SOC_CLK_SEL_S);
WRITE_PERI_REG(CPU_PER_CONF_REG, 0x01);
INFO("[APP] Setup CPU run as 160MHz - Done\n");
#endif
//nvs_flash_init();
/* added by me:
load wifi setting
if available
if wifi setting are available try to connect
(
get wifi setting and configure it
strncpy((char *)ap_config.ap.ssid, (char *)param->softap_ssid.ssid, param->softap_ssid.ssid_len);
ap_config.ap.ssid_len = param->softap_ssid.ssid_len;
strncpy((char *)ap_config.ap.password, (char *)param->softap_passwd.passwd, param->softap_passwd.passwd_len);
esp_wifi_set_config(WIFI_IF_AP, &ap_config);
esp_wifi_connect();
what if it fails to connect to set SSID and PASSWORD After restart?
than how to check the attempt failed and wait for retry?
if connected start MQTT client
)
else if no wifi settings available init BLUFI and start BLUFI(call to
blufi_security_init();
esp_ble_gap_register_callback(example_gap_event_handler);
esp_blufi_register_callbacks(&example_callbacks);
esp_blufi_profile_init();
)
*/
/*
on LED indicator
if connected to AP, LED as blue color(simultanously connected to device, MQTT or )
if connecting to AP, blinking BLUE
if failed to connect to AP, blinking orange
if in BLUFI configuring mode set blinking yellow color
if connected to device in BLUFI device blinking
if MQTT connected green
if connecting to MQTT blinking green
if failed to connect to MQTT blinking restored
*/
wifi_conn_init();
}
Thanks.
Who is online
Users browsing this forum: Google [Bot], yimeng and 49 guests