ESP32+SIM800C=cannot connect to internet
Posted: Wed Jul 20, 2022 5:50 pm
Hello everyone!
I'm using ESP32 board Lilygo T-Call with AXP192 PMIC and I'm trying to connect it to Internet using firmware based on ESP-IDF.
I can get information from the modem but I can't connect to the network.
I tried to change auth params, APN, username and password but no result. NETLIGHT doesn't blink frequently even.
Code to connect to Internet
Output:
Output with modem network disabled
Parameters used:
APN internet.beeline.ru
user beeline
password beeline
I'm using ESP32 board Lilygo T-Call with AXP192 PMIC and I'm trying to connect it to Internet using firmware based on ESP-IDF.
I can get information from the modem but I can't connect to the network.
I tried to change auth params, APN, username and password but no result. NETLIGHT doesn't blink frequently even.
Code to connect to Internet
Code: Select all
//extern "C" {
#include <stdio.h>
#include "esp_log.h"
#include "driver/i2c.h"
#include "mqtt_client.h"
#include "esp_modem.h"
#include "esp_modem_netif.h"
//#include "esp_modem_config.h"
#include "sim800.h"
#include "sdkconfig.h"
#include "freertos/event_groups.h"
//}
#include "axp20x.h"
#include "esp_netif.h"
#include "esp_netif_ppp.h"
static const char *TAG = "AXP20x";
#define _I2C_NUMBER(num) I2C_NUM_##num
#define I2C_NUMBER(num) _I2C_NUMBER(num)
#define AXP_ISR_GPIO (gpio_num_t)CONFIG_AXPxxx_INTERRUPT_PIN /*!< axp power chip interrupt Pin*/
#define GPIO_INPUT_PIN_SEL (1ULL<<AXP_ISR_GPIO)
#define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL /*!< gpio number for I2C master clock */
#define I2C_MASTER_SDA_IO CONFIG_I2C_MASTER_SDA /*!< gpio number for I2C master data */
#define I2C_MASTER_NUM I2C_NUMBER(CONFIG_I2C_MASTER_PORT_NUM) /*!< I2C port number for master dev */
#define I2C_MASTER_FREQ_HZ CONFIG_I2C_MASTER_FREQUENCY /*!< I2C master clock frequency */
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
#define READ_BIT I2C_MASTER_READ /*!< I2C master read */
#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
#define ACK_VAL (i2c_ack_type_t)0x0 /*!< I2C ack value */
#define NACK_VAL (i2c_ack_type_t)0x1 /*!< I2C nack value */
//#define MODEM_RST (gpio_num_t)5
#define MODEM_PWRKEY (gpio_num_t)4
#define MODEM_POWER_ON (gpio_num_t)25
#define MODEM_DTR (gpio_num_t)32
#define MODEM_RI (gpio_num_t)33
#define BROKER_URL "mqtt://mqtt.eclipseprojects.io"
//static const char *TAG = "pppos_example";
static EventGroupHandle_t event_group = NULL;
static const int CONNECT_BIT = BIT0;
static const int STOP_BIT = BIT1;
static const int GOT_DATA_BIT = BIT2;
AXP20X_Class axp;
static xQueueHandle gpio_evt_queue = NULL;
static void IRAM_ATTR axp_isr_handler(void *arg)
{
uint32_t gpio_num = (uint32_t) arg;
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
}
static void axp_irq_init()
{
gpio_config_t io_conf;
//enable interrupt
io_conf.intr_type = GPIO_INTR_NEGEDGE;
//set as input mode
io_conf.mode = GPIO_MODE_INPUT;
//bit mask of the pins that you want to set
io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
//disable pull-down mode
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
//enable pull-up mode
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
//configure GPIO with the given settings
gpio_config(&io_conf);
//change gpio intrrupt type for one pin
gpio_set_intr_type(AXP_ISR_GPIO, GPIO_INTR_NEGEDGE);
//install gpio isr service
gpio_install_isr_service(0);
//hook isr handler for specific gpio pin
gpio_isr_handler_add(AXP_ISR_GPIO, axp_isr_handler, (void *) AXP_ISR_GPIO);
//create a queue to handle gpio event from isr
gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
}
/**
* @brief i2c master initialization
*/
static esp_err_t i2c_master_init(void)
{
int i2c_master_port = I2C_MASTER_NUM;
i2c_config_t conf;
conf.mode = I2C_MODE_MASTER;
conf.sda_io_num = I2C_MASTER_SDA_IO;
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
conf.scl_io_num = I2C_MASTER_SCL_IO;
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
conf.master.clk_speed = I2C_MASTER_FREQ_HZ;
i2c_param_config(i2c_master_port, &conf);
return i2c_driver_install(i2c_master_port, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
}
/**
* @brief apx library i2c read callblack
*/
uint8_t twi_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint8_t len)
{
if (len == 0) {
return ESP_OK;
}
if (data == NULL) {
return ESP_FAIL;
}
i2c_cmd_handle_t cmd;
cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (dev_addr << 1) | WRITE_BIT, ACK_CHECK_EN);
i2c_master_write_byte(cmd, reg_addr, ACK_CHECK_EN);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
if (ret != ESP_OK) {
return ESP_FAIL;
}
cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (dev_addr << 1) | READ_BIT, ACK_CHECK_EN);
if (len > 1) {
i2c_master_read(cmd, data, len - 1, ACK_VAL);
}
i2c_master_read_byte(cmd, &data[len - 1], NACK_VAL);
i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
return ret;
}
/**
* @brief apx library i2c write callblack
*/
uint8_t twi_write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint8_t len)
{
if (data == NULL) {
return ESP_FAIL;
}
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (dev_addr << 1) | WRITE_BIT, ACK_CHECK_EN);
i2c_master_write_byte(cmd, reg_addr, ACK_CHECK_EN);
i2c_master_write(cmd, data, len, ACK_CHECK_EN);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
return ret;
}
void setupModem()
{
gpio_reset_pin(MODEM_PWRKEY);
gpio_reset_pin(MODEM_POWER_ON);
#ifdef MODEM_RST
// Keep reset high
// pinMode(MODEM_RST, OUTPUT);
// digitalWrite(MODEM_RST, HIGH);
gpio_reset_pin(MODEM_RST);
gpio_set_direction(MODEM_RST, GPIO_MODE_OUTPUT);
gpio_set_level(MODEM_RST, 1);
#endif
// pinMode(MODEM_PWRKEY, OUTPUT);
// pinMode(MODEM_POWER_ON, OUTPUT);
gpio_set_direction(MODEM_PWRKEY, GPIO_MODE_OUTPUT);
gpio_set_direction(MODEM_POWER_ON, GPIO_MODE_OUTPUT);
// Turn on the Modem power first
// digitalWrite(MODEM_POWER_ON, HIGH);
gpio_set_level(MODEM_POWER_ON, 1);
// Pull down PWRKEY for more than 1 second according to manual requirements
// digitalWrite(MODEM_PWRKEY, HIGH);
// delay(100);
// digitalWrite(MODEM_PWRKEY, LOW);
// delay(1000);
// digitalWrite(MODEM_PWRKEY, HIGH);
gpio_set_level(MODEM_PWRKEY, 1);
vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(MODEM_PWRKEY, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
gpio_set_level(MODEM_PWRKEY, 1);
// Initialize the indicator as an output
// pinMode(LED_GPIO, OUTPUT);
// digitalWrite(LED_GPIO, LED_OFF);
ESP_LOGI(TAG, "Modem power has been setup");
}
static void modem_event_handler(void *event_handler_arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
switch (event_id) {
case ESP_MODEM_EVENT_PPP_START:
ESP_LOGI(TAG, "Modem PPP Started");
break;
case ESP_MODEM_EVENT_PPP_STOP:
ESP_LOGI(TAG, "Modem PPP Stopped");
xEventGroupSetBits(event_group, STOP_BIT);
break;
case ESP_MODEM_EVENT_UNKNOWN:
ESP_LOGW(TAG, "Unknown line received: %s", (char *)event_data);
break;
default:
break;
}
}
static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event)
{
esp_mqtt_client_handle_t client = event->client;
int msg_id;
switch (event->event_id) {
case MQTT_EVENT_CONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
msg_id = esp_mqtt_client_subscribe(client, "/topic/esp-pppos", 0);
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
break;
case MQTT_EVENT_DISCONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
break;
case MQTT_EVENT_SUBSCRIBED:
ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
msg_id = esp_mqtt_client_publish(client, "/topic/esp-pppos", "esp32-pppos", 0, 0, 0);
ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);
break;
case MQTT_EVENT_UNSUBSCRIBED:
ESP_LOGI(TAG, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_PUBLISHED:
ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_DATA:
ESP_LOGI(TAG, "MQTT_EVENT_DATA");
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
printf("DATA=%.*s\r\n", event->data_len, event->data);
xEventGroupSetBits(event_group, GOT_DATA_BIT);
break;
case MQTT_EVENT_ERROR:
ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
break;
default:
ESP_LOGI(TAG, "MQTT other event id: %d", event->event_id);
break;
}
return ESP_OK;
}
static void on_ppp_changed(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
ESP_LOGI(TAG, "PPP state changed event %d", event_id);
if (event_id == NETIF_PPP_ERRORUSER) {
/* User interrupted event from esp-netif */
esp_netif_t *netif = *(esp_netif_t**)event_data;
ESP_LOGI(TAG, "User interrupted event from netif:%p", netif);
}
if (event_id == NETIF_PPP_PHASE_DEAD) {
ESP_LOGI(TAG, "NETIF_PPP_PHASE_DEAD");
}
if (event_id == NETIF_PPP_PHASE_MASTER) {
ESP_LOGI(TAG, "NETIF_PPP_PHASE_MASTER");
}
if (event_id == NETIF_PPP_PHASE_HOLDOFF) {
ESP_LOGI(TAG, "NETIF_PPP_PHASE_HOLDOFF");
}
if (event_id == NETIF_PPP_PHASE_INITIALIZE) {
ESP_LOGI(TAG, "NETIF_PPP_PHASE_INITIALIZE");
}
if (event_id == NETIF_PPP_PHASE_SERIALCONN) {
ESP_LOGI(TAG, "NETIF_PPP_PHASE_SERIALCONN");
}
if (event_id == NETIF_PPP_PHASE_DORMANT) {
ESP_LOGI(TAG, "NETIF_PPP_PHASE_DORMANT");
}
if (event_id == NETIF_PPP_PHASE_ESTABLISH) {
ESP_LOGI(TAG, "NETIF_PPP_PHASE_ESTABLISH");
}
if (event_id == NETIF_PPP_PHASE_AUTHENTICATE) {
ESP_LOGI(TAG, "NETIF_PPP_PHASE_AUTHENTICATE");
}
if (event_id == NETIF_PPP_PHASE_CALLBACK) {
ESP_LOGI(TAG, "NETIF_PPP_PHASE_CALLBACK");
}
if (event_id == NETIF_PPP_PHASE_NETWORK) {
ESP_LOGI(TAG, "NETIF_PPP_PHASE_NETWORK");
}
if (event_id == NETIF_PPP_PHASE_RUNNING) {
ESP_LOGI(TAG, "NETIF_PPP_PHASE_RUNNING");
}
if (event_id == NETIF_PPP_PHASE_TERMINATE) {
ESP_LOGI(TAG, "NETIF_PPP_PHASE_TERMINATE");
}
if (event_id == NETIF_PPP_PHASE_DISCONNECT) {
ESP_LOGI(TAG, "NETIF_PPP_PHASE_DISCONNECT");
}
if (event_id == NETIF_PPP_CONNECT_FAILED) {
ESP_LOGI(TAG, "NETIF_PPP_CONNECT_FAILED");
}
}
static void on_ip_event(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
ESP_LOGD(TAG, "IP event! %d", event_id);
if (event_id == IP_EVENT_PPP_GOT_IP) {
esp_netif_dns_info_t dns_info;
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
esp_netif_t *netif = event->esp_netif;
ESP_LOGI(TAG, "Modem Connect to PPP Server");
ESP_LOGI(TAG, "~~~~~~~~~~~~~~");
ESP_LOGI(TAG, "IP : " IPSTR, IP2STR(&event->ip_info.ip));
ESP_LOGI(TAG, "Netmask : " IPSTR, IP2STR(&event->ip_info.netmask));
ESP_LOGI(TAG, "Gateway : " IPSTR, IP2STR(&event->ip_info.gw));
esp_netif_get_dns_info(netif, (esp_netif_dns_type_t)0, &dns_info);
ESP_LOGI(TAG, "Name Server1: " IPSTR, IP2STR(&dns_info.ip.u_addr.ip4));
esp_netif_get_dns_info(netif, (esp_netif_dns_type_t)1, &dns_info);
ESP_LOGI(TAG, "Name Server2: " IPSTR, IP2STR(&dns_info.ip.u_addr.ip4));
ESP_LOGI(TAG, "~~~~~~~~~~~~~~");
xEventGroupSetBits(event_group, CONNECT_BIT);
ESP_LOGI(TAG, "GOT ip event!!!");
} else if (event_id == IP_EVENT_PPP_LOST_IP) {
ESP_LOGI(TAG, "Modem Disconnect from PPP Server");
} else if (event_id == IP_EVENT_GOT_IP6) {
ESP_LOGI(TAG, "GOT IPv6 event!");
ip_event_got_ip6_t *event = (ip_event_got_ip6_t *)event_data;
ESP_LOGI(TAG, "Got IPv6 address " IPV6STR, IPV62STR(event->ip6_info.ip));
}
}
extern "C" void app_main(void)
{
printf("System start\n");
vTaskDelay(500 / portTICK_PERIOD_MS);
ESP_ERROR_CHECK(i2c_master_init());
axp_irq_init();
if (axp.begin((axp_com_fptr_t)twi_read, (axp_com_fptr_t)twi_write, AXP192_SLAVE_ADDRESS)) {
ESP_LOGE(TAG, "Error init axp20x !!!");
while (1);
}
ESP_LOGI(TAG, "Success init axp20x !!!");
axp.setPowerOutPut(AXP202_DCDC3, AXP202_ON);
axp.setPowerOutPut(AXP202_EXTEN, AXP202_ON);
axp.setPowerOutPut(AXP202_LDO2, AXP202_ON);
axp.setPowerOutPut(AXP202_LDO4, AXP202_ON);
axp.setPowerOutPut(AXP202_DCDC2, AXP202_ON);
axp.setLDO4Voltage(AXP202_LDO4_1800MV);
axp.setLDO3Voltage(3500);
axp.setPowerOutPut(AXP202_LDO3, AXP202_ON);
if ( axp.isDCDC2Enable()) {
ESP_LOGI(TAG, "DC2: %u mV", axp.getDCDC2Voltage());
} else {
ESP_LOGI(TAG, "DC2: DISABLE");
}
if (axp.isDCDC3Enable()) {
ESP_LOGI(TAG, "DC3: %u mV", axp.getDCDC3Voltage());
} else {
ESP_LOGI(TAG, "DC3: DISABLE");
}
if (axp.isLDO2Enable()) {
ESP_LOGI(TAG, "LDO2: %u mV", axp.getLDO2Voltage());
} else {
ESP_LOGI(TAG, "LDO2: DISABLE");
}
if (axp.isLDO3Enable()) {
ESP_LOGI(TAG, "LDO3: %u mV", axp.getLDO3Voltage());
} else {
ESP_LOGI(TAG, "LDO3: DISABLE");
}
if (axp.isLDO4Enable()) {
ESP_LOGI(TAG, "LDO4: %u mV", axp.getLDO4Voltage());
} else {
ESP_LOGI(TAG, "LDO4: DISABLE");
}
if (axp.isExtenEnable()) {
ESP_LOGI(TAG, "Exten: ENABLE");
} else {
ESP_LOGI(TAG, "Exten: DISABLE");
}
//When the chip is axp192 / 173, the allowed values are 0 ~ 15,
//corresponding to the axp1xx_charge_current_t enumeration
// axp.setChargeControlCur(AXP1XX_CHARGE_CUR_550MA);
//axp202 allows maximum charging current of 1800mA, minimum 300mA
axp.setChargeControlCur(300);
ESP_LOGI(TAG, "setChargeControlCur:%u", axp.getChargeControlCur());
//! Enable all irq channel
axp.enableIRQ(AXP202_ALL_IRQ, true);
axp.clearIRQ();
//! Turn off unused power
// axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
// axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
// axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
// axp.setPowerOutPut(AXP192_DCDC2, AXP202_OFF);
// axp.setPowerOutPut(AXP192_EXTEN, AXP202_OFF);
//! Do not turn off DC3, it is powered by esp32
// axp.setPowerOutPut(AXP192_DCDC3, AXP202_ON);
// Set the charging indicator to turn off
// Turn it off to save current consumption
// axp.setChgLEDMode(AXP20X_LED_OFF);
// Set the charging indicator to flash once per second
// axp.setChgLEDMode(AXP20X_LED_BLINK_1HZ);
//! Use axp192 adc get voltage info
axp.adc1Enable(AXP202_VBUS_VOL_ADC1 | AXP202_VBUS_CUR_ADC1 | AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true);
// float vbus_v = axp.getVbusVoltage();
// float vbus_c = axp.getVbusCurrent();
// float batt_v = axp.getBattVoltage();
// axp.getBattPercentage(); // axp192 is not support percentage
//Serial.printf("VBUS:%.2f mV %.2f mA ,BATTERY: %.2f\n", vbus_v, vbus_c, batt_v);
setupModem();
vTaskDelay(10000 / portTICK_PERIOD_MS);
#if CONFIG_LWIP_PPP_PAP_SUPPORT
esp_netif_auth_type_t auth_type = NETIF_PPP_AUTHTYPE_PAP;
#elif CONFIG_LWIP_PPP_CHAP_SUPPORT
esp_netif_auth_type_t auth_type = NETIF_PPP_AUTHTYPE_CHAP;
#elif !defined(CONFIG_EXAMPLE_MODEM_PPP_AUTH_NONE)
#error "Unsupported AUTH Negotiation"
#endif
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &on_ip_event, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &on_ppp_changed, NULL));
event_group = xEventGroupCreate();
/* create dte object */
//esp_modem_dte_config_t config = ESP_MODEM_DTE_DEFAULT_CONFIG();
esp_modem_dte_config_t config = {0};
/* setup UART specific configuration based on kconfig options */
config.port_num = UART_NUM_1;
config.data_bits = UART_DATA_8_BITS;
config.stop_bits = UART_STOP_BITS_1;
config.parity = UART_PARITY_DISABLE;
config.baud_rate = 115200;
config.flow_control = MODEM_FLOW_CONTROL_NONE;
config.tx_io_num = CONFIG_EXAMPLE_MODEM_UART_TX_PIN;
config.rx_io_num = CONFIG_EXAMPLE_MODEM_UART_RX_PIN;
config.rts_io_num = CONFIG_EXAMPLE_MODEM_UART_RTS_PIN;
config.cts_io_num = CONFIG_EXAMPLE_MODEM_UART_CTS_PIN;
config.rx_buffer_size = CONFIG_EXAMPLE_MODEM_UART_RX_BUFFER_SIZE;
config.tx_buffer_size = CONFIG_EXAMPLE_MODEM_UART_TX_BUFFER_SIZE;
config.event_queue_size = CONFIG_EXAMPLE_MODEM_UART_EVENT_QUEUE_SIZE;
config.event_task_stack_size = CONFIG_EXAMPLE_MODEM_UART_EVENT_TASK_STACK_SIZE;
config.event_task_priority = CONFIG_EXAMPLE_MODEM_UART_EVENT_TASK_PRIORITY;
config.dte_buffer_size = CONFIG_EXAMPLE_MODEM_UART_RX_BUFFER_SIZE / 2;
modem_dte_t *dte = esp_modem_dte_init(&config);
/* Register event handler */
ESP_ERROR_CHECK(esp_modem_set_event_handler(dte, modem_event_handler, ESP_EVENT_ANY_ID, NULL));
// Init netif object
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_PPP();
esp_netif_t *esp_netif = esp_netif_new(&cfg);
assert(esp_netif);
void *modem_netif_adapter = esp_modem_netif_setup(dte);
esp_modem_netif_set_default_handlers(modem_netif_adapter, esp_netif);
modem_dce_t *dce = NULL;
/* create dce object */
#if CONFIG_EXAMPLE_MODEM_DEVICE_SIM800
dce = sim800_init(dte);
#elif CONFIG_EXAMPLE_MODEM_DEVICE_BG96
dce = bg96_init(dte);
#elif CONFIG_EXAMPLE_MODEM_DEVICE_SIM7600
dce = sim7600_init(dte);
#else
#error "Unsupported DCE"
#endif
assert(dce != NULL);
ESP_ERROR_CHECK(dce->set_flow_ctrl(dce, MODEM_FLOW_CONTROL_NONE));
ESP_ERROR_CHECK(dce->store_profile(dce));
#if !defined(CONFIG_EXAMPLE_MODEM_PPP_AUTH_NONE) && (defined(CONFIG_LWIP_PPP_PAP_SUPPORT) || defined(CONFIG_LWIP_PPP_CHAP_SUPPORT))
esp_netif_ppp_set_auth(esp_netif, auth_type, CONFIG_EXAMPLE_MODEM_PPP_AUTH_USERNAME, CONFIG_EXAMPLE_MODEM_PPP_AUTH_PASSWORD);
#endif
/* attach the modem to the network interface */
esp_netif_attach(esp_netif, modem_netif_adapter);
/* Wait for IP address */
xEventGroupWaitBits(event_group, CONNECT_BIT, pdTRUE, pdTRUE, portMAX_DELAY);
/* Config MQTT */
esp_mqtt_client_config_t mqtt_config = {0};
mqtt_config.uri = BROKER_URL;
mqtt_config.event_handle = mqtt_event_handler;
//};
esp_mqtt_client_handle_t mqtt_client = esp_mqtt_client_init(&mqtt_config);
esp_mqtt_client_start(mqtt_client);
uint32_t io_num;
for (;;) {
float vbus_v = axp.getVbusVoltage();
float vbus_c = axp.getVbusCurrent();
float batt_v = axp.getBattVoltage();
ESP_LOGI(TAG, "VBUS:%.2f mV %.2f mA ,BATTERY: %.2f", vbus_v, vbus_c, batt_v);
ESP_ERROR_CHECK(dce->get_operator_name(dce));
/* Print Module ID, Operator, IMEI, IMSI */
ESP_LOGI(TAG, "Module: %s", dce->name);
ESP_LOGI(TAG, "Operator: %s", dce->oper);
ESP_LOGI(TAG, "IMEI: %s", dce->imei);
ESP_LOGI(TAG, "IMSI: %s", dce->imsi);
/* Get signal quality */
uint32_t rssi = 0, ber = 0;
ESP_ERROR_CHECK(dce->get_signal_quality(dce, &rssi, &ber));
ESP_LOGI(TAG, "rssi: %d, ber: %d", rssi, ber);
if (xQueueReceive(gpio_evt_queue, &io_num, 2000 / portTICK_PERIOD_MS)) {
if (io_num == AXP_ISR_GPIO) {
axp.readIRQ();
if (axp.isPEKShortPressIRQ()) {
ESP_LOGI(TAG, "AXP202 PEK key Click");
}
if(axp.isChargingIRQ()) {
ESP_LOGI(TAG, "AXP202 Battery charging in progress");
}
if(axp.isChargingDoneIRQ()) {
ESP_LOGI(TAG, "AXP202 Battery charged");
}
axp.clearIRQ();
}
}
vTaskDelay(10);
}
}
Code: Select all
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6608
load:0x40078000,len:14788
ho 0 tail 12 room 4
load:0x40080400,len:3792
entry 0x40080694
I (29) boot: ESP-IDF v4.4.1 2nd stage bootloader
I (29) boot: compile time 14:42:03
I (29) boot: chip revision: 1
I (31) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (39) boot.esp32: SPI Speed : 40MHz
I (43) boot.esp32: SPI Mode : DIO
I (48) boot.esp32: SPI Flash Size : 2MB
I (52) boot: Enabling RNG early entropy source...
I (58) boot: Partition Table:
I (61) boot: ## Label Usage Type ST Offset Length
I (69) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (76) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (83) boot: 2 factory factory app 00 00 00010000 00100000
I (91) boot: End of partition table
I (95) boot_comm: chip revision: 1, min. application chip revision: 0
I (102) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=1aec0h (110272) map
I (151) esp_image: segment 1: paddr=0002aee8 vaddr=3ffb0000 size=02470h ( 9328) load
I (155) esp_image: segment 2: paddr=0002d360 vaddr=40080000 size=02cb8h ( 11448) load
I (161) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=6d0b8h (446648) map
I (327) esp_image: segment 4: paddr=0009d0e0 vaddr=40082cb8 size=0a750h ( 42832) load
I (344) esp_image: segment 5: paddr=000a7838 vaddr=50000000 size=00010h ( 16) load
I (351) boot: Loaded app from partition at offset 0x10000
I (351) boot: Disabling RNG early entropy source...
I (365) cpu_start: Pro cpu up.
I (365) cpu_start: Starting app cpu, entry point is 0x4008126c
I (0) cpu_start: App cpu up.
I (379) cpu_start: Pro cpu start user code
I (379) cpu_start: cpu freq: 160000000
I (379) cpu_start: Application information:
I (383) cpu_start: Project name: esp32-modem-project
I (389) cpu_start: App version: 1
I (394) cpu_start: Compile time: Jul 20 2022 18:49:36
I (400) cpu_start: ELF file SHA256: 031c9a5f7ea18317...
I (406) cpu_start: ESP-IDF: v4.4.1
I (411) heap_init: Initializing. RAM available for dynamic allocation:
I (418) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (424) heap_init: At 3FFB3E60 len 0002C1A0 (176 KiB): DRAM
I (430) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (437) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (443) heap_init: At 4008D408 len 00012BF8 (74 KiB): IRAM
I (451) spi_flash: detected chip: generic
I (454) spi_flash: flash io: dio
W (458) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (472) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
System start
I (1478) gpio: GPIO[35]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulld own: 0| Intr:2
I (1478) AXP20x: Success init axp20x !!!
I (1488) AXP20x: DC2: 1800 mV
I (1488) AXP20x: DC3: 3300 mV
I (1488) AXP20x: LDO2: 3300 mV
I (1488) AXP20x: LDO3: 3300 mV
I (1498) AXP20x: LDO4: DISABLE
I (1498) AXP20x: Exten: ENABLE
I (1498) AXP20x: setChargeControlCur:15
I (1518) gpio: GPIO[4]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldo wn: 0| Intr:0
I (1518) gpio: GPIO[25]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulld own: 0| Intr:0
I (2628) AXP20x: Modem power has been setup
I (12628) uart: queue free spaces: 30
E (12648) esp-modem: handle line failed
W (12658) AXP20x: Unknown line received: +COPS: 0
I (12808) AXP20x: Modem PPP Started
I (12808) AXP20x: PPP state changed event 259
I (12808) AXP20x: NETIF_PPP_PHASE_INITIALIZE
I (12808) AXP20x: PPP state changed event 262
I (12808) AXP20x: NETIF_PPP_PHASE_ESTABLISH
I (12828) AXP20x: PPP state changed event 263
I (12828) AXP20x: NETIF_PPP_PHASE_AUTHENTICATE
I (12838) AXP20x: PPP state changed event 265
I (12838) AXP20x: NETIF_PPP_PHASE_NETWORK
I (12858) AXP20x: PPP state changed event 262
I (12858) AXP20x: NETIF_PPP_PHASE_ESTABLISH
I (18858) AXP20x: PPP state changed event 268
I (18858) AXP20x: NETIF_PPP_PHASE_DISCONNECT
I (18858) AXP20x: PPP state changed event 256
I (18858) AXP20x: NETIF_PPP_PHASE_DEAD
I (18858) esp-netif_lwip-ppp: Connection lost
I (18868) AXP20x: Modem Disconnect from PPP Server
Code: Select all
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6608
load:0x40078000,len:14788
ho 0 tail 12 room 4
load:0x40080400,len:3792
entry 0x40080694
I (28) boot: ESP-IDF v4.4.1 2nd stage bootloader
I (29) boot: compile time 14:42:03
I (29) boot: chip revision: 1
I (31) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (38) boot.esp32: SPI Speed : 40MHz
I (43) boot.esp32: SPI Mode : DIO
I (48) boot.esp32: SPI Flash Size : 2MB
I (52) boot: Enabling RNG early entropy source...
I (58) boot: Partition Table:
I (61) boot: ## Label Usage Type ST Offset Length
I (68) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (76) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (83) boot: 2 factory factory app 00 00 00010000 00100000
I (91) boot: End of partition table
I (95) boot_comm: chip revision: 1, min. application chip revision: 0
I (102) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=12c78h ( 76920) map
I (139) esp_image: segment 1: paddr=00022ca0 vaddr=3ffb0000 size=023cch ( 9164) load
I (142) esp_image: segment 2: paddr=00025074 vaddr=40080000 size=0afa4h ( 44964) load
I (163) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=45b2ch (285484) map
I (266) esp_image: segment 4: paddr=00075b54 vaddr=4008afa4 size=0215ch ( 8540) load
I (270) esp_image: segment 5: paddr=00077cb8 vaddr=50000000 size=00010h ( 16) load
I (279) boot: Loaded app from partition at offset 0x10000
I (279) boot: Disabling RNG early entropy source...
I (295) cpu_start: Pro cpu up.
I (295) cpu_start: Starting app cpu, entry point is 0x40081240
I (0) cpu_start: App cpu up.
I (309) cpu_start: Pro cpu start user code
I (309) cpu_start: cpu freq: 160000000
I (310) cpu_start: Application information:
I (314) cpu_start: Project name: esp32-modem-project
I (320) cpu_start: App version: 1
I (324) cpu_start: Compile time: Jul 20 2022 18:49:36
I (330) cpu_start: ELF file SHA256: 6e95eb54ca398127...
I (336) cpu_start: ESP-IDF: v4.4.1
I (342) heap_init: Initializing. RAM available for dynamic allocation:
I (349) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (355) heap_init: At 3FFB3C90 len 0002C370 (176 KiB): DRAM
I (361) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (367) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (374) heap_init: At 4008D100 len 00012F00 (75 KiB): IRAM
I (381) spi_flash: detected chip: generic
I (385) spi_flash: flash io: dio
W (388) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (403) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
System start
I (1408) gpio: GPIO[35]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulld own: 0| Intr:2
I (1408) AXP20x: Success init axp20x !!!
I (1418) AXP20x: DC2: 1800 mV
I (1418) AXP20x: DC3: 3300 mV
I (1418) AXP20x: LDO2: 3300 mV
I (1418) AXP20x: LDO3: 3300 mV
I (1428) AXP20x: LDO4: DISABLE
I (1428) AXP20x: Exten: ENABLE
I (1428) AXP20x: setChargeControlCur:15
I (1448) gpio: GPIO[4]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldo wn: 0| Intr:0
I (1448) gpio: GPIO[25]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulld own: 0| Intr:0
I (2558) AXP20x: Modem power has been setup
I (12558) uart: queue free spaces: 30
E (12578) esp-modem: handle line failed
W (12578) AXP20x: Unknown line received: +COPS: 0
I (12588) AXP20x: VBUS:5028.60 mV 0.00 mA ,BATTERY: 4195.40
E (12588) esp-modem: handle line failed
W (12588) AXP20x: Unknown line received: +COPS: 0
I (12598) AXP20x: Module: SIMCOM_SIM800C
I (12598) AXP20x: Operator:
I (12608) AXP20x: IMEI: 862205152863801
I (12608) AXP20x: IMSI: 250991639436458
E (12618) esp-modem: handle line failed
W (12618) AXP20x: Unknown line received: SMS Ready
I (12628) AXP20x: rssi: 0, ber: 0
I (14728) AXP20x: VBUS:5030.30 mV 0.00 mA ,BATTERY: 4195.40
E (14728) esp-modem: handle line failed
W (14728) AXP20x: Unknown line received: +COPS: 0
I (14728) AXP20x: Module: SIMCOM_SIM800C
I (14738) AXP20x: Operator:
I (14738) AXP20x: IMEI: 862205152863801
I (14748) AXP20x: IMSI: 250991639436458
I (14758) AXP20x: rssi: 31, ber: 0
I (16858) AXP20x: VBUS:5006.50 mV 14.62 mA ,BATTERY: 4195.40
I (16868) AXP20x: Module: SIMCOM_SIM800C
I (16868) AXP20x: Operator: "Bee Line GSM"
I (16868) AXP20x: IMEI: 862205152863801
I (16868) AXP20x: IMSI: 250991639436458
I (16878) AXP20x: rssi: 31, ber: 5
I (18978) AXP20x: VBUS:5032.00 mV 0.00 mA ,BATTERY: 4195.40
I (18988) AXP20x: Module: SIMCOM_SIM800C
I (18988) AXP20x: Operator: "Bee Line GSM"
I (18988) AXP20x: IMEI: 862205152863801
I (18988) AXP20x: IMSI: 250991639436458
I (18998) AXP20x: rssi: 31, ber: 5
I (21098) AXP20x: VBUS:5033.70 mV 0.00 mA ,BATTERY: 4195.40
I (21108) AXP20x: Module: SIMCOM_SIM800C
I (21108) AXP20x: Operator: "Bee Line GSM"
I (21108) AXP20x: IMEI: 862205152863801
I (21108) AXP20x: IMSI: 250991639436458
I (21118) AXP20x: rssi: 31, ber: 5
I (23218) AXP20x: VBUS:5030.30 mV 0.00 mA ,BATTERY: 4195.40
I (23228) AXP20x: Module: SIMCOM_SIM800C
I (23228) AXP20x: Operator: "Bee Line GSM"
I (23228) AXP20x: IMEI: 862205152863801
I (23228) AXP20x: IMSI: 250991639436458
I (23238) AXP20x: rssi: 31, ber: 5
I (25338) AXP20x: VBUS:5025.20 mV 0.00 mA ,BATTERY: 4195.40
I (25348) AXP20x: Module: SIMCOM_SIM800C
I (25348) AXP20x: Operator: "Bee Line GSM"
I (25348) AXP20x: IMEI: 862205152863801
I (25348) AXP20x: IMSI: 250991639436458
I (25358) AXP20x: rssi: 31, ber: 5
I (27458) AXP20x: VBUS:5035.40 mV 0.00 mA ,BATTERY: 4195.40
I (27468) AXP20x: Module: SIMCOM_SIM800C
I (27468) AXP20x: Operator: "Bee Line GSM"
I (27468) AXP20x: IMEI: 862205152863801
I (27468) AXP20x: IMSI: 250991639436458
I (27478) AXP20x: rssi: 31, ber: 5
I (29578) AXP20x: VBUS:5026.90 mV 0.00 mA ,BATTERY: 4195.40
I (29588) AXP20x: Module: SIMCOM_SIM800C
I (29588) AXP20x: Operator: "Bee Line GSM"
I (29588) AXP20x: IMEI: 862205152863801
I (29588) AXP20x: IMSI: 250991639436458
I (29598) AXP20x: rssi: 31, ber: 0
...
APN internet.beeline.ru
user beeline
password beeline