Removed experiments with modem
This commit is contained in:
@ -19,7 +19,6 @@ set(dependencies
|
||||
esp_wifi
|
||||
driver
|
||||
esp_eth
|
||||
esp_modem
|
||||
|
||||
cxx-ring-buffer
|
||||
cpputils
|
||||
|
@ -43,14 +43,6 @@
|
||||
#include <soc/io_mux_reg.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PPP_SUPPORT
|
||||
#include <cxx_include/esp_modem_dce_module.hpp>
|
||||
#include <cxx_include/esp_modem_dte.hpp>
|
||||
#include <esp_modem_config.h>
|
||||
#include <cxx_include/esp_modem_api.hpp>
|
||||
#include <esp_netif_defaults.h>
|
||||
#endif
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <fmt/core.h>
|
||||
#include <strutils.h>
|
||||
@ -321,9 +313,6 @@ void handleWifiEvents(const config &config, TickType_t xTicksToWait);
|
||||
#ifdef CONFIG_ETH_ENABLED
|
||||
std::expected<void, std::string> eth_begin(const config &config, const eth_config ð);
|
||||
#endif
|
||||
#ifdef CONFIG_PPP_SUPPORT
|
||||
esp_err_t modem_init();
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
void init(const config &config)
|
||||
@ -367,10 +356,6 @@ void init(const config &config)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PPP_SUPPORT
|
||||
modem_init();
|
||||
#endif
|
||||
|
||||
if (config.ap)
|
||||
{
|
||||
ESP_LOGI(TAG, "AccessPoint %.*s", config.ap->ssid.size(), config.ap->ssid.data());
|
||||
@ -2886,361 +2871,5 @@ std::expected<void, std::string> eth_begin(const config &config, const eth_confi
|
||||
return {};
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PPP_SUPPORT
|
||||
esp_err_t modem_init()
|
||||
{
|
||||
constexpr gpio_num_t pwrPin = GPIO_NUM_4;
|
||||
constexpr gpio_num_t pwrEnablePin = GPIO_NUM_27;
|
||||
constexpr gpio_num_t resetPin = GPIO_NUM_17;
|
||||
constexpr gpio_num_t txPin = GPIO_NUM_16;
|
||||
constexpr gpio_num_t rxPin = GPIO_NUM_34;
|
||||
constexpr gpio_num_t rtsPin = GPIO_NUM_19;
|
||||
constexpr gpio_num_t ctsPin = GPIO_NUM_18;
|
||||
const auto baudRate = 115200;
|
||||
|
||||
{
|
||||
const gpio_config_t config {
|
||||
.pin_bit_mask = 1ULL << pwrPin,
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
|
||||
if (const auto result = gpio_config(&config); result != ESP_OK)
|
||||
ESP_LOGE(TAG, "gpio_config() failed %s", esp_err_to_name(result));
|
||||
|
||||
if (const auto result = gpio_set_level(pwrPin, true); result != ESP_OK)
|
||||
ESP_LOGE(TAG, "gpio_set_level() failed with %s", esp_err_to_name(result));
|
||||
}
|
||||
{
|
||||
const gpio_config_t config {
|
||||
.pin_bit_mask = 1ULL << pwrEnablePin,
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
|
||||
if (const auto result = gpio_config(&config); result != ESP_OK)
|
||||
ESP_LOGE(TAG, "gpio_config() failed %s", esp_err_to_name(result));
|
||||
|
||||
if (const auto result = gpio_set_level(pwrEnablePin, true); result != ESP_OK)
|
||||
ESP_LOGE(TAG, "gpio_set_level() failed with %s", esp_err_to_name(result));
|
||||
}
|
||||
|
||||
{
|
||||
const gpio_config_t config {
|
||||
.pin_bit_mask = 1ULL << resetPin,
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
|
||||
if (const auto result = gpio_config(&config); result != ESP_OK)
|
||||
ESP_LOGE(TAG, "gpio_config() failed %s", esp_err_to_name(result));
|
||||
|
||||
if (const auto result = gpio_set_level(resetPin, false); result != ESP_OK)
|
||||
ESP_LOGE(TAG, "gpio_set_level() failed with %s", esp_err_to_name(result));
|
||||
|
||||
espcpputils::delay(50ms);
|
||||
|
||||
if (const auto result = gpio_set_level(resetPin, true); result != ESP_OK)
|
||||
ESP_LOGE(TAG, "gpio_set_level() failed with %s", esp_err_to_name(result));
|
||||
|
||||
espcpputils::delay(500ms);
|
||||
}
|
||||
{
|
||||
const gpio_config_t config {
|
||||
.pin_bit_mask = 1ULL << txPin,
|
||||
.mode = GPIO_MODE_INPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
|
||||
if (const auto result = gpio_config(&config); result != ESP_OK)
|
||||
ESP_LOGE(TAG, "gpio_config() failed %s", esp_err_to_name(result));
|
||||
}
|
||||
{
|
||||
const gpio_config_t config {
|
||||
.pin_bit_mask = 1ULL << rxPin,
|
||||
.mode = GPIO_MODE_INPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
|
||||
if (const auto result = gpio_config(&config); result != ESP_OK)
|
||||
ESP_LOGE(TAG, "gpio_config() failed %s", esp_err_to_name(result));
|
||||
}
|
||||
|
||||
constexpr uart_port_t host_uart_num = UART_NUM_0;
|
||||
constexpr uart_port_t uart_num = UART_NUM_1;
|
||||
|
||||
{
|
||||
const uart_config_t uart_config = {
|
||||
.baud_rate = baudRate,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||
.rx_flow_ctrl_thresh = 122,
|
||||
.source_clk = UART_SCLK_APB,
|
||||
// .source_clk = UART_SCLK_REF_TICK,
|
||||
};
|
||||
if (const auto result = uart_param_config(uart_num, &uart_config); result != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "uart_param_config() failed with %s", esp_err_to_name(result));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (const auto result = uart_set_pin(uart_num, txPin, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); result != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "uart_set_pin() failed with %s", esp_err_to_name(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
const int uart_buffer_size = 1024 * 2;
|
||||
if (const auto result = uart_driver_install(uart_num, uart_buffer_size, uart_buffer_size, 10, nullptr, 0); result != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "uart_driver_install() failed with %s", esp_err_to_name(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "you now have the power to talk to the modem:");
|
||||
|
||||
while (true)
|
||||
{
|
||||
#if defined(CONFIG_ESP_TASK_WDT_PANIC) || defined(CONFIG_ESP_TASK_WDT)
|
||||
if (const auto result = esp_task_wdt_reset(); result != ESP_OK)
|
||||
ESP_LOGE(TAG, "esp_task_wdt_reset() failed with %s", esp_err_to_name(result));
|
||||
#endif
|
||||
|
||||
size_t length{};
|
||||
if (const auto result = uart_get_buffered_data_len(host_uart_num, &length); result != ESP_OK)
|
||||
{
|
||||
ESP_LOGW(TAG, "uart_get_buffered_data_len() failed with %s", esp_err_to_name(result));
|
||||
}
|
||||
else if (length)
|
||||
{
|
||||
char data[length];
|
||||
length = uart_read_bytes(host_uart_num, data, length, 0);
|
||||
|
||||
if (const auto written = uart_write_bytes(uart_num, data, length); written < 0)
|
||||
ESP_LOGE(TAG, "uart_write_bytes() failed with %i", written);
|
||||
else if (written != length)
|
||||
ESP_LOGW(TAG, "uart_write_bytes() did not write all bytes %i vs %i", written, length);
|
||||
}
|
||||
|
||||
if (const auto result = uart_get_buffered_data_len(uart_num, &length); result != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "uart_get_buffered_data_len() failed with %s", esp_err_to_name(result));
|
||||
vTaskDelay(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!length)
|
||||
{
|
||||
vTaskDelay(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
char data[length];
|
||||
length = uart_read_bytes(uart_num, data, length, 0);
|
||||
|
||||
if (!length)
|
||||
{
|
||||
vTaskDelay(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("%.*s", length, data);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
/* Configure and create the DTE */
|
||||
esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG();
|
||||
/* setup UART specific configuration based on kconfig options */
|
||||
dte_config.uart_config.baud_rate = baudRate;
|
||||
dte_config.uart_config.tx_io_num = txPin;
|
||||
dte_config.uart_config.rx_io_num = rxPin;
|
||||
dte_config.uart_config.rts_io_num = rtsPin;
|
||||
dte_config.uart_config.cts_io_num = ctsPin;
|
||||
dte_config.uart_config.flow_control = ESP_MODEM_FLOW_CONTROL_NONE; //ESP_MODEM_FLOW_CONTROL_NONE, ESP_MODEM_FLOW_CONTROL_SW, ESP_MODEM_FLOW_CONTROL_HW
|
||||
|
||||
auto dte = esp_modem::create_uart_dte(&dte_config);
|
||||
if (!dte)
|
||||
{
|
||||
ESP_LOGE(TAG, "create_uart_dte() failed");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
/* Configure the DCE */
|
||||
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("business.gprsinternet"); // thingsmobile
|
||||
|
||||
/* Configure the PPP netif */
|
||||
esp_netif_config_t netif_ppp_config = ESP_NETIF_DEFAULT_PPP();
|
||||
|
||||
/* Create the PPP and DCE objects */
|
||||
esp_netif_t *esp_netif = esp_netif_new(&netif_ppp_config);
|
||||
if (!esp_netif)
|
||||
{
|
||||
ESP_LOGE(TAG, "esp_netif_new() failed");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
auto dce = esp_modem::create_SIM7600_dce(&dce_config, dte, esp_netif);
|
||||
if (!dce)
|
||||
{
|
||||
ESP_LOGE(TAG, "create_SIM7600_dce() failed");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "waiting for ATREADY");
|
||||
if (const auto result = esp_modem::dce_commands::generic_command(dte.get(), "", "ATREADY", "ERROR", 30000); result == esp_modem::command_result::OK)
|
||||
ESP_LOGI(TAG, "Successfully waited for ATREADY");
|
||||
else
|
||||
{
|
||||
ESP_LOGW(TAG, "Waiting for ATREADY failed %i", std::to_underlying(result));
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
if (dte_config.uart_config.flow_control == ESP_MODEM_FLOW_CONTROL_HW)
|
||||
{
|
||||
again:
|
||||
if (const auto result = dce->set_flow_control(2, 2); result != esp_modem::command_result::OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to set the set_flow_control mode %i", std::to_underlying(result));
|
||||
#if defined(CONFIG_ESP_TASK_WDT_PANIC) || defined(CONFIG_ESP_TASK_WDT)
|
||||
if (const auto result = esp_task_wdt_reset(); result != ESP_OK)
|
||||
ESP_LOGE(TAG, "esp_task_wdt_reset() failed with %s", esp_err_to_name(result));
|
||||
#endif
|
||||
espcpputils::delay(1s);
|
||||
goto again;
|
||||
}
|
||||
else
|
||||
ESP_LOGI(TAG, "set_flow_control OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI(TAG, "not set_flow_control, because 2-wire mode active.");
|
||||
}
|
||||
|
||||
std::string str;
|
||||
|
||||
// ESP_LOGI(TAG, "get_imei()...");
|
||||
// if (const auto result = dce->get_imei(str); result == esp_modem::command_result::OK)
|
||||
// ESP_LOGI(TAG, "IMEI: %s", str.c_str());
|
||||
// else
|
||||
// ESP_LOGE(TAG, "get_imei() failed with %i", std::to_underlying(result));
|
||||
|
||||
const auto work_between = [&](){
|
||||
espcpputils::delay(1000ms);
|
||||
ESP_LOGI(TAG, "get_imei()...");
|
||||
if (const auto result = dce->get_imei(str); result == esp_modem::command_result::OK)
|
||||
ESP_LOGI(TAG, "IMEI: %s", str.c_str());
|
||||
else
|
||||
ESP_LOGE(TAG, "get_imei() failed with %i", std::to_underlying(result));
|
||||
|
||||
#if defined(CONFIG_ESP_TASK_WDT_PANIC) || defined(CONFIG_ESP_TASK_WDT)
|
||||
if (const auto result = esp_task_wdt_reset(); result != ESP_OK)
|
||||
ESP_LOGE(TAG, "esp_task_wdt_reset() failed with %s", esp_err_to_name(result));
|
||||
#endif
|
||||
espcpputils::delay(1000ms);
|
||||
};
|
||||
|
||||
work_between();
|
||||
|
||||
ESP_LOGI(TAG, "test0 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+DUALSIM?", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test1 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+SWITCHSIM?", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test2 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+BINDSIM?", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test3 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+CSPN?", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test4 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+BINDSIM=1", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test5 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+BSPN?", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test6 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+DUALSIMURC?", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test7 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+BINDSIM?", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test8 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+BINDSIM?", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test9 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+BINDSIM=?", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test10 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+BINDSIM=1", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test11 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+BINDSIM=2", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test12 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+SWITCHSIM?", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test13 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+SWITCHSIM=?", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test14 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+SWITCHSIM=1", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
ESP_LOGI(TAG, "test15 %i", std::to_underlying(esp_modem::dce_commands::generic_command(dte.get(), "AT+SWITCHSIM=2", "PASS", "ERROR", 50000)));
|
||||
work_between();
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
ESP_LOGI(TAG, "get_operator_name()...");
|
||||
if (const auto result = dce->get_operator_name(str); result == esp_modem::command_result::OK)
|
||||
{
|
||||
ESP_LOGI(TAG, "Operator name: %s", str.c_str());
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "get_operator_name() failed with %i", std::to_underlying(result));
|
||||
espcpputils::delay(500ms);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto i = 0; i < 10; i++)
|
||||
{
|
||||
if (dce->set_mode(esp_modem::modem_mode::CMUX_MODE))
|
||||
{
|
||||
ESP_LOGI(TAG, "Modem has correctly entered multiplexed command/data mode");
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to configure multiplexed command mode...");
|
||||
|
||||
work_between();
|
||||
|
||||
continue;
|
||||
|
||||
//return ESP_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
ESP_LOGI(TAG, "get_imsi()...");
|
||||
if (const auto result = dce->get_imsi(str); result == esp_modem::command_result::OK)
|
||||
{
|
||||
ESP_LOGI(TAG, "IMSI: %s", str.c_str());
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "get_imsi() failed with %i", std::to_underlying(result));
|
||||
espcpputils::delay(500ms);
|
||||
}
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif
|
||||
} // namespace
|
||||
} // namespace wifi_stack
|
||||
|
Reference in New Issue
Block a user