diff --git a/Kconfig b/Kconfig index dc8bd85..d221262 100644 --- a/Kconfig +++ b/Kconfig @@ -1,639 +1,646 @@ -menu "webguiapp configuration" - config WEBGUIAPP_PROJECT_VER - string "webguiapp Project version" - default "0.0.0.0000" - help - Project version code - config WEBGUIAPP_HOSTNAME - string "Default host name" - default "DEVICE_HOSTNAME" - - config WEBGUIAPP_USERNAME - string "Default user name" - default "user" - - config WEBGUIAPP_USERPASS - string "Default user password" - default "password" - - config MAIN_FUNCTIONAL_BUTTON_GPIO - int "Main functional button GPIO" - range -1 34 - default 15 - help - Set the GPIO number for main system button. Mainly needed for settings default reset. If not - used set -1 - - config DEBUG_MODE_ENABLE - bool "Enabled JTAG debug" - default n - help - Switch on JTAG debug mode. Otherwise pins 12-15 used as normal GPIO - - - menu "SPI settings" - config WEBGUIAPP_SPI_ENABLE - bool "Enabled SPI interface" - default y - help - Set enabled SPI bus - - if WEBGUIAPP_SPI_ENABLE - - config SPI_HOST - int "SPI Host Number" - range 0 2 - default 1 - help - Set the SPI host used. - - config SPI_SCLK_GPIO - int "SPI SCLK GPIO number" - range 0 33 - default 18 - help - Set the GPIO number used by SPI SCLK. - - config SPI_MOSI_GPIO - int "SPI MOSI GPIO number" - range 0 33 - default 23 - help - Set the GPIO number used by SPI MOSI. - - config SPI_MISO_GPIO - int "SPI MISO GPIO number" - range 0 33 - default 19 - help - Set the GPIO number used by SPI MISO. - - endif - endmenu - - menu "I2C settings" - config WEBGUIAPP_I2C_ENABLE - bool "Enabled I2C interface" - default y - help - Set enabled I2C bus - - if WEBGUIAPP_I2C_ENABLE - - config I2C_HOST - int "I2C Host Number" - range 0 1 - default 0 - help - Set the I2C host used. - - config I2C_SCL_GPIO - int "I2C SCL GPIO number" - range 0 34 - default 22 - - config I2C_SDA_GPIO - int "I2C SDA GPIO number" - range 0 34 - default 21 - - config I2C_CLOCK - int "I2C clock" - range 400000 1000000 - default 400000 - - endif - endmenu - - - - menu "WiFi settings" - config WEBGUIAPP_WIFI_ENABLE - bool "Enabled WIFI interface" - default y - help - Set enabled WiFi - - if WEBGUIAPP_WIFI_ENABLE - - config WEBGUIAPP_WIFI_ON - bool "Default WiFi switched on" - default y - - config WEBGUIAPP_WIFI_DHCP_ON - bool "Default WiFi DHCP switched on" - default y - - config WEBGUIAPP_WIFI_SSID_AP - string "WiFi SSID AP" - default "YourAP" - help - SSID (network name) in AP mode. - - config WEBGUIAPP_WIFI_KEY_AP - string "WiFi key AP" - default "123456789" - help - WiFi key (WPA or WPA2) in AP mode. - - config WEBGUIAPP_WIFI_SSID_STA - string "WiFi SSID STA" - default "YourSTA" - help - SSID (network name) in client mode. - - config WEBGUIAPP_WIFI_KEY_STA - string "WiFi key STA" - default "123456789" - help - WiFi key (WPA or WPA2) in client mode. - - config WEBGUIAPP_WIFI_IP_AP - string "Default IP address in AP mode" - default "192.168.150.1" - - config WEBGUIAPP_WIFI_IP_STA - string "Default IP address in STA mode" - default "192.168.150.1" - - config WEBGUIAPP_WIFI_MASK_STA - string "Default network mask in STA mode" - default "255.255.255.0" - - config WEBGUIAPP_WIFI_GATEWAY_STA - string "Default gateway in STA mode" - default "192.168.150.1" - - - endif - endmenu - - - - menu "Ethernet settings" - config WEBGUIAPP_ETHERNET_ENABLE - bool "Enabled ETHERNET interface" - default n - help - Set enabled Ethernet adapter - - if WEBGUIAPP_ETHERNET_ENABLE - - config WEBGUIAPP_ETHERNET_ON - bool "Default Ethernet switched on" - default y - - config WEBGUIAPP_ETH_IP_DEFAULT - string "Default IP address" - default "192.168.160.1" - - config WEBGUIAPP_ETH_MASK_DEFAULT - string "Default network mask" - default "255.255.255.0" - - config WEBGUIAPP_ETH_GATEWAY_DEFAULT - string "Default gateway" - default "192.168.160.1" - - config WEBGUIAPP_ETHERNET_DHCP_DEFAULT - bool "Default Ethernet DHCP client on" - default n - - config GPIO_RANGE_MIN - int - default 0 - - config GPIO_RANGE_MAX - int - default 36 if IDF_TARGET_ESP32 - default 46 if IDF_TARGET_ESP32S2 - default 19 if IDF_TARGET_ESP32C3 - default 48 if IDF_TARGET_ESP32S3 - - config USE_INTERNAL_ETHERNET - depends on IDF_TARGET_ESP32 - select ETH_USE_ESP32_EMAC - bool "Internal EMAC" - help - Use internal Ethernet MAC controller. - - if USE_INTERNAL_ETHERNET - choice ETH_PHY_MODEL - prompt "Ethernet PHY Device" - default ETH_PHY_IP101 - help - Select the Ethernet PHY device to use in the example. - - config ETH_PHY_IP101 - bool "IP101" - help - IP101 is a single port 10/100 MII/RMII/TP/Fiber Fast Ethernet Transceiver. - Goto http://www.icplus.com.tw/pp-IP101G.html for more information about it. - - config ETH_PHY_RTL8201 - bool "RTL8201/SR8201" - help - RTL8201F/SR8201F is a single port 10/100Mb Ethernet Transceiver with auto MDIX. - Goto http://www.corechip-sz.com/productsview.asp?id=22 for more information about it. - - config ETH_PHY_LAN87XX - bool "LAN87xx" - help - Below chips are supported: - LAN8710A LAN8720A LAN8740A/LAN8741ALAN8742A - - config ETH_PHY_DP83848 - bool "DP83848" - help - DP83848 is a single port 10/100Mb/s Ethernet Physical Layer Transceiver. - Goto http://www.ti.com/product/DP83848J for more information about it. - - config ETH_PHY_KSZ8041 - bool "KSZ8041" - help - The KSZ8041 is a single supply 10Base-T/100Base-TX Physical Layer Transceiver. - Goto https://www.microchip.com/wwwproducts/en/KSZ8041 for more information about it. - - config ETH_PHY_KSZ8081 - bool "KSZ8081" - help - The KSZ8081 is a single supply 10Base-T/100Base-TX Physical Layer Transceiver. - Goto https://www.microchip.com/wwwproducts/en/KSZ8081 for more information about it. - endchoice # EXAMPLE_ETH_PHY_MODEL - - config ETH_MDC_GPIO - int "SMI MDC GPIO number" - range GPIO_RANGE_MIN GPIO_RANGE_MAX - default 23 - help - Set the GPIO number used by SMI MDC. - - config ETH_MDIO_GPIO - int "SMI MDIO GPIO number" - range GPIO_RANGE_MIN GPIO_RANGE_MAX - default 18 - help - Set the GPIO number used by SMI MDIO. - - config ETH_PHY_RST_GPIO - int "PHY Reset GPIO number" - range -1 GPIO_RANGE_MAX - default 5 - help - Set the GPIO number used to reset PHY chip. - Set to -1 to disable PHY chip hardware reset. - - config ETH_PHY_ADDR - int "PHY Address" - range 0 31 - default 1 - help - Set PHY address according your board schematic. - endif # USE_INTERNAL_ETHERNET - - config USE_SPI_ETHERNET - bool "SPI Ethernet" - default y - select WEBGUIAPP_SPI_ENABLE - help - Use external SPI-Ethernet module(s). - - if USE_SPI_ETHERNET - config SPI_ETHERNETS_NUM - int "Number of SPI Ethernet modules to use at a time" - range 1 2 - default 1 - help - Set the number of SPI Ethernet modules you want to use at a time. Multiple SPI modules can be connected - to one SPI interface and can be separately accessed based on state of associated Chip Select (CS). - - choice ETHERNET_TYPE_SPI - prompt "Ethernet SPI" - default W5500 - help - Select which kind of Ethernet will be used in the example. - - config DM9051 - bool "DM9051 Module" - select ETH_SPI_ETHERNET_DM9051 - help - Select external SPI-Ethernet module (DM9051). - - config KSZ8851SNL - bool "KSZ8851SNL Module" - select ETH_SPI_ETHERNET_KSZ8851SNL - help - Select external SPI-Ethernet module (KSZ8851SNL). - - config W5500 - bool "W5500 Module" - select ETH_SPI_ETHERNET_W5500 - help - Select external SPI-Ethernet module (W5500). - endchoice - - - config ETH_SPI_CLOCK_MHZ - int "SPI clock speed (MHz)" - range 5 80 - default 12 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32C3 - default 36 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 - help - Set the clock speed (MHz) of SPI interface. - - config ETH_SPI_CS0_GPIO - int "SPI CS0 GPIO number for SPI Ethernet module #1" - range GPIO_RANGE_MIN GPIO_RANGE_MAX - default 15 if IDF_TARGET_ESP32 - default 10 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 - help - Set the GPIO number used by SPI CS0, i.e. Chip Select associated with the first SPI Eth module). - - config ETH_SPI_CS1_GPIO - depends on SPI_ETHERNETS_NUM > 1 - int "SPI CS1 GPIO number for SPI Ethernet module #2" - range GPIO_RANGE_MIN GPIO_RANGE_MAX - default 32 if IDF_TARGET_ESP32 - default 7 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 - default 8 if IDF_TARGET_ESP32C3 - help - Set the GPIO number used by SPI CS1, i.e. Chip Select associated with the second SPI Eth module. - - config ETH_SPI_INT0_GPIO - int "Interrupt GPIO number SPI Ethernet module #1" - range 0 39 - default 4 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 - help - Set the GPIO number used by the first SPI Ethernet module interrupt line. - - config ETH_SPI_INT1_GPIO - depends on SPI_ETHERNETS_NUM > 1 - int "Interrupt GPIO number SPI Ethernet module #2" - range 0 36 - default 33 if IDF_TARGET_ESP32 - default 5 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 - help - Set the GPIO number used by the second SPI Ethernet module interrupt line. - - config ETH_SPI_PHY_RST0_GPIO - int "PHY Reset GPIO number of SPI Ethernet Module #1" - range -1 GPIO_RANGE_MAX - default -1 - help - Set the GPIO number used to reset PHY chip on the first SPI Ethernet module. - Set to -1 to disable PHY chip hardware reset. - - config ETH_SPI_PHY_RST1_GPIO - depends on SPI_ETHERNETS_NUM > 1 - int "PHY Reset GPIO number of SPI Ethernet Module #2" - range -1 GPIO_RANGE_MAX - default -1 - help - Set the GPIO number used to reset PHY chip on the second SPI Ethernet module. - Set to -1 to disable PHY chip hardware reset. - - config ETH_SPI_PHY_ADDR0 - int "PHY Address of SPI Ethernet Module #1" - range 0 31 - default 1 - help - Set the first SPI Ethernet module PHY address according your board schematic. - - config ETH_SPI_PHY_ADDR1 - depends on SPI_ETHERNETS_NUM > 1 - int "PHY Address of SPI Ethernet Module #2" - range 0 31 - default 1 - help - Set the second SPI Ethernet module PHY address according your board schematic. - endif # USE_SPI_ETHERNET - endif - endmenu - - - - menu "GPRS settings" - config WEBGUIAPP_GPRS_ENABLE - bool "Enabled GPRS PPP interface" - default n - help - Set enabled GPRS adapter - - if WEBGUIAPP_GPRS_ENABLE - - config WEBGUIAPP_GPRS_ON - bool "Default GPRS switched on" - default n - - choice MODEM_DEVICE - prompt "Choose supported modem device (DCE)" - default MODEM_DEVICE_SIM800 - help - Select modem device connected to the ESP DTE. - config MODEM_DEVICE_SIM800 - bool "SIM800" - help - SIMCom SIM800L is a GSM/GPRS module. - It supports Quad-band 850/900/1800/1900MHz. - config MODEM_DEVICE_BG96 - bool "BG96" - help - Quectel BG96 is a series of LTE Cat M1/Cat NB1/EGPRS module. - config MODEM_DEVICE_SIM7600 - bool "SIM7600" - help - SIM7600 is Multi-Band LTE-TDD/LTE-FDD/HSPA+ and GSM/GPRS/EDGE module - endchoice - - config MODEM_PPP_APN - string "Set MODEM APN" - default "internet" - help - Set APN (Access Point Name), a logical name to choose data network - - config MODEM_PPP_AUTH_USERNAME - string "Set username for authentication" - default "gdata" - depends on !MODEM_PPP_AUTH_NONE - help - Set username for PPP Authentication. - - config MODEM_PPP_AUTH_PASSWORD - string "Set password for authentication" - default "gdata" - depends on !MODEM_PPP_AUTH_NONE - help - Set password for PPP Authentication. - - config MODEM_PPP_AUTH_NONE - bool "Skip PPP authentication" - default n - help - Set to true for the PPP client to skip authentication - - - config MODEM_NEED_SIM_PIN - bool "SIM PIN needed" - default n - help - Enable to set SIM PIN before starting the example - - config MODEM_SIM_PIN - string "Set SIM PIN" - default "1234" - depends on MODEM_NEED_SIM_PIN - help - Pin to unlock the SIM - - menu "UART Configuration" - config MODEM_UART_TX_PIN - int "TXD Pin Number" - default 17 - range 0 31 - help - Pin number of UART TX. - - config MODEM_UART_RX_PIN - int "RXD Pin Number" - default 16 - range 0 31 - help - Pin number of UART RX. - - config MODEM_UART_RTS_PIN - int "RTS Pin Number" - default 0 - range 0 31 - help - Pin number of UART RTS. - - config MODEM_UART_CTS_PIN - int "CTS Pin Number" - default 0 - range 0 31 - help - Pin number of UART CTS. - - config MODEM_UART_EVENT_TASK_STACK_SIZE - int "UART Event Task Stack Size" - range 2000 6000 - default 2048 - help - Stack size of UART event task. - - config MODEM_UART_EVENT_TASK_PRIORITY - int "UART Event Task Priority" - range 3 22 - default 5 - help - Priority of UART event task. - - config MODEM_UART_EVENT_QUEUE_SIZE - int "UART Event Queue Size" - range 10 40 - default 30 - help - Length of UART event queue. - - config MODEM_UART_PATTERN_QUEUE_SIZE - int "UART Pattern Queue Size" - range 10 40 - default 20 - help - Length of UART pattern queue. - - config MODEM_UART_TX_BUFFER_SIZE - int "UART TX Buffer Size" - range 256 2048 - default 512 - help - Buffer size of UART TX buffer. - - config MODEM_UART_RX_BUFFER_SIZE - int "UART RX Buffer Size" - range 256 2048 - default 1024 - help - Buffer size of UART RX buffer. - endmenu - - endif - endmenu - - menu "MQTT settings" - config WEBGUIAPP_MQTT_ENABLE - bool "Enabled MQTT transport" - default y - - if WEBGUIAPP_MQTT_ENABLE - config WEBGUIAPP_MQTT_CLIENTS_NUM - int "Number of MQTT clients" - range 1 2 - default 2 - - config WEBGUIAPP_MQTT_ON - bool "Enable MQTT client" - default y - - config WEBGUIAPP_MQTT_MAX_TOPIC_LENGTH - int "Max topic length" - range 32 512 - default 128 - - config WEBGUIAPP_MQTT_SERVER_URL - string "MQTT server URL" - default "myfirstmqttserver.com" - - config WEBGUIAPP_MQTT_SERVER_PORT - int "MQTT server port" - range 1 65535 - default 1883 - - config WEBGUIAPP_MQTT_CLIENT_ID_1 - string "MQTT_1 client ID prefix" - default "DEV1" - - if WEBGUIAPP_MQTT_CLIENTS_NUM > 1 - config WEBGUIAPP_MQTT_CLIENT_ID_2 - string "MQTT_2 client ID prefix" - default "DEV2" - endif - - config WEBGUIAPP_MQTT_SYSTEM_NAME - string "MQTT global system name" - default "SYSTEMNAME" - - config WEBGUIAPP_MQTT_GROUP_NAME - string "MQTT group name" - default "GROUPNAME" - - config WEBGUIAPP_MQTT_USERNAME - string "MQTT user name" - default "username" - - config WEBGUIAPP_MQTT_PASSWORD - string "MQTT user password" - default "password" - - endif - endmenu - - if WEBGUIAPP_WIFI_ENABLE || WEBGUIAPP_ETHERNET_ENABLE || WEBGUIAPP_GPRS_ENABLE - menu "DNS settings" - - config WEBGUIAPP_DNS1_ADDRESS_DEFAULT - string "DNS1" - default "8.8.8.8" - - config WEBGUIAPP_DNS2_ADDRESS_DEFAULT - string "DNS2" - default "8.8.4.4" - - config WEBGUIAPP_DNS3_ADDRESS_DEFAULT - string "DNS3" - default "1.1.1.1" - - endmenu - endif - +menu "webguiapp configuration" + config WEBGUIAPP_PROJECT_VER + string "webguiapp Project version" + default "0.0.0.0000" + help + Project version code + config WEBGUIAPP_HOSTNAME + string "Default host name" + default "DEVICE_HOSTNAME" + + config WEBGUIAPP_USERNAME + string "Default user name" + default "user" + + config WEBGUIAPP_USERPASS + string "Default user password" + default "password" + + config MAIN_FUNCTIONAL_BUTTON_GPIO + int "Main functional button GPIO" + range -1 34 + default 15 + help + Set the GPIO number for main system button. Mainly needed for settings default reset. If not + used set -1 + + config DEBUG_MODE_ENABLE + bool "Enabled JTAG debug" + default n + help + Switch on JTAG debug mode. Otherwise pins 12-15 used as normal GPIO + + + menu "SPI settings" + config WEBGUIAPP_SPI_ENABLE + bool "Enabled SPI interface" + default y + help + Set enabled SPI bus + + if WEBGUIAPP_SPI_ENABLE + + config SPI_HOST + int "SPI Host Number" + range 0 2 + default 1 + help + Set the SPI host used. + + config SPI_SCLK_GPIO + int "SPI SCLK GPIO number" + range 0 33 + default 18 + help + Set the GPIO number used by SPI SCLK. + + config SPI_MOSI_GPIO + int "SPI MOSI GPIO number" + range 0 33 + default 23 + help + Set the GPIO number used by SPI MOSI. + + config SPI_MISO_GPIO + int "SPI MISO GPIO number" + range 0 33 + default 19 + help + Set the GPIO number used by SPI MISO. + + endif + endmenu + + menu "I2C settings" + config WEBGUIAPP_I2C_ENABLE + bool "Enabled I2C interface" + default y + help + Set enabled I2C bus + + if WEBGUIAPP_I2C_ENABLE + + config I2C_HOST + int "I2C Host Number" + range 0 1 + default 0 + help + Set the I2C host used. + + config I2C_SCL_GPIO + int "I2C SCL GPIO number" + range 0 34 + default 22 + + config I2C_SDA_GPIO + int "I2C SDA GPIO number" + range 0 34 + default 21 + + config I2C_CLOCK + int "I2C clock" + range 400000 1000000 + default 400000 + + endif + endmenu + + + + menu "WiFi settings" + config WEBGUIAPP_WIFI_ENABLE + bool "Enabled WIFI interface" + default y + help + Set enabled WiFi + + if WEBGUIAPP_WIFI_ENABLE + + config WEBGUIAPP_WIFI_ON + bool "Default WiFi switched on" + default y + + config WEBGUIAPP_WIFI_DHCP_ON + bool "Default WiFi DHCP switched on" + default y + + config WEBGUIAPP_WIFI_SSID_AP + string "WiFi SSID AP" + default "YourAP" + help + SSID (network name) in AP mode. + + config WEBGUIAPP_WIFI_KEY_AP + string "WiFi key AP" + default "123456789" + help + WiFi key (WPA or WPA2) in AP mode. + + config WEBGUIAPP_WIFI_SSID_STA + string "WiFi SSID STA" + default "YourSTA" + help + SSID (network name) in client mode. + + config WEBGUIAPP_WIFI_KEY_STA + string "WiFi key STA" + default "123456789" + help + WiFi key (WPA or WPA2) in client mode. + + config WEBGUIAPP_WIFI_IP_AP + string "Default IP address in AP mode" + default "192.168.150.1" + + config WEBGUIAPP_WIFI_IP_STA + string "Default IP address in STA mode" + default "192.168.150.1" + + config WEBGUIAPP_WIFI_MASK_STA + string "Default network mask in STA mode" + default "255.255.255.0" + + config WEBGUIAPP_WIFI_GATEWAY_STA + string "Default gateway in STA mode" + default "192.168.150.1" + + + endif + endmenu + + + + menu "Ethernet settings" + config WEBGUIAPP_ETHERNET_ENABLE + bool "Enabled ETHERNET interface" + default n + help + Set enabled Ethernet adapter + + if WEBGUIAPP_ETHERNET_ENABLE + + config WEBGUIAPP_ETHERNET_ON + bool "Default Ethernet switched on" + default y + + config WEBGUIAPP_ETH_IP_DEFAULT + string "Default IP address" + default "192.168.160.1" + + config WEBGUIAPP_ETH_MASK_DEFAULT + string "Default network mask" + default "255.255.255.0" + + config WEBGUIAPP_ETH_GATEWAY_DEFAULT + string "Default gateway" + default "192.168.160.1" + + config WEBGUIAPP_ETHERNET_DHCP_DEFAULT + bool "Default Ethernet DHCP client on" + default n + + config GPIO_RANGE_MIN + int + default 0 + + config GPIO_RANGE_MAX + int + default 36 if IDF_TARGET_ESP32 + default 46 if IDF_TARGET_ESP32S2 + default 19 if IDF_TARGET_ESP32C3 + default 48 if IDF_TARGET_ESP32S3 + + config USE_INTERNAL_ETHERNET + depends on IDF_TARGET_ESP32 + select ETH_USE_ESP32_EMAC + bool "Internal EMAC" + help + Use internal Ethernet MAC controller. + + if USE_INTERNAL_ETHERNET + choice ETH_PHY_MODEL + prompt "Ethernet PHY Device" + default ETH_PHY_IP101 + help + Select the Ethernet PHY device to use in the example. + + config ETH_PHY_IP101 + bool "IP101" + help + IP101 is a single port 10/100 MII/RMII/TP/Fiber Fast Ethernet Transceiver. + Goto http://www.icplus.com.tw/pp-IP101G.html for more information about it. + + config ETH_PHY_RTL8201 + bool "RTL8201/SR8201" + help + RTL8201F/SR8201F is a single port 10/100Mb Ethernet Transceiver with auto MDIX. + Goto http://www.corechip-sz.com/productsview.asp?id=22 for more information about it. + + config ETH_PHY_LAN87XX + bool "LAN87xx" + help + Below chips are supported: + LAN8710A LAN8720A LAN8740A/LAN8741ALAN8742A + + config ETH_PHY_DP83848 + bool "DP83848" + help + DP83848 is a single port 10/100Mb/s Ethernet Physical Layer Transceiver. + Goto http://www.ti.com/product/DP83848J for more information about it. + + config ETH_PHY_KSZ8041 + bool "KSZ8041" + help + The KSZ8041 is a single supply 10Base-T/100Base-TX Physical Layer Transceiver. + Goto https://www.microchip.com/wwwproducts/en/KSZ8041 for more information about it. + + config ETH_PHY_KSZ8081 + bool "KSZ8081" + help + The KSZ8081 is a single supply 10Base-T/100Base-TX Physical Layer Transceiver. + Goto https://www.microchip.com/wwwproducts/en/KSZ8081 for more information about it. + endchoice # EXAMPLE_ETH_PHY_MODEL + + config ETH_MDC_GPIO + int "SMI MDC GPIO number" + range GPIO_RANGE_MIN GPIO_RANGE_MAX + default 23 + help + Set the GPIO number used by SMI MDC. + + config ETH_MDIO_GPIO + int "SMI MDIO GPIO number" + range GPIO_RANGE_MIN GPIO_RANGE_MAX + default 18 + help + Set the GPIO number used by SMI MDIO. + + config ETH_PHY_RST_GPIO + int "PHY Reset GPIO number" + range -1 GPIO_RANGE_MAX + default 5 + help + Set the GPIO number used to reset PHY chip. + Set to -1 to disable PHY chip hardware reset. + + config ETH_PHY_ADDR + int "PHY Address" + range 0 31 + default 1 + help + Set PHY address according your board schematic. + endif # USE_INTERNAL_ETHERNET + + config USE_SPI_ETHERNET + bool "SPI Ethernet" + default y + select WEBGUIAPP_SPI_ENABLE + help + Use external SPI-Ethernet module(s). + + if USE_SPI_ETHERNET + config SPI_ETHERNETS_NUM + int "Number of SPI Ethernet modules to use at a time" + range 1 2 + default 1 + help + Set the number of SPI Ethernet modules you want to use at a time. Multiple SPI modules can be connected + to one SPI interface and can be separately accessed based on state of associated Chip Select (CS). + + choice ETHERNET_TYPE_SPI + prompt "Ethernet SPI" + default W5500 + help + Select which kind of Ethernet will be used in the example. + + config DM9051 + bool "DM9051 Module" + select ETH_SPI_ETHERNET_DM9051 + help + Select external SPI-Ethernet module (DM9051). + + config KSZ8851SNL + bool "KSZ8851SNL Module" + select ETH_SPI_ETHERNET_KSZ8851SNL + help + Select external SPI-Ethernet module (KSZ8851SNL). + + config W5500 + bool "W5500 Module" + select ETH_SPI_ETHERNET_W5500 + help + Select external SPI-Ethernet module (W5500). + endchoice + + + config ETH_SPI_CLOCK_MHZ + int "SPI clock speed (MHz)" + range 5 80 + default 12 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32C3 + default 36 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + help + Set the clock speed (MHz) of SPI interface. + + config ETH_SPI_CS0_GPIO + int "SPI CS0 GPIO number for SPI Ethernet module #1" + range GPIO_RANGE_MIN GPIO_RANGE_MAX + default 15 if IDF_TARGET_ESP32 + default 10 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 + help + Set the GPIO number used by SPI CS0, i.e. Chip Select associated with the first SPI Eth module). + + config ETH_SPI_CS1_GPIO + depends on SPI_ETHERNETS_NUM > 1 + int "SPI CS1 GPIO number for SPI Ethernet module #2" + range GPIO_RANGE_MIN GPIO_RANGE_MAX + default 32 if IDF_TARGET_ESP32 + default 7 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + default 8 if IDF_TARGET_ESP32C3 + help + Set the GPIO number used by SPI CS1, i.e. Chip Select associated with the second SPI Eth module. + + config ETH_SPI_INT0_GPIO + int "Interrupt GPIO number SPI Ethernet module #1" + range 0 39 + default 4 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 + help + Set the GPIO number used by the first SPI Ethernet module interrupt line. + + config ETH_SPI_INT1_GPIO + depends on SPI_ETHERNETS_NUM > 1 + int "Interrupt GPIO number SPI Ethernet module #2" + range 0 36 + default 33 if IDF_TARGET_ESP32 + default 5 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 + help + Set the GPIO number used by the second SPI Ethernet module interrupt line. + + config ETH_SPI_PHY_RST0_GPIO + int "PHY Reset GPIO number of SPI Ethernet Module #1" + range -1 GPIO_RANGE_MAX + default -1 + help + Set the GPIO number used to reset PHY chip on the first SPI Ethernet module. + Set to -1 to disable PHY chip hardware reset. + + config ETH_SPI_PHY_RST1_GPIO + depends on SPI_ETHERNETS_NUM > 1 + int "PHY Reset GPIO number of SPI Ethernet Module #2" + range -1 GPIO_RANGE_MAX + default -1 + help + Set the GPIO number used to reset PHY chip on the second SPI Ethernet module. + Set to -1 to disable PHY chip hardware reset. + + config ETH_SPI_PHY_ADDR0 + int "PHY Address of SPI Ethernet Module #1" + range 0 31 + default 1 + help + Set the first SPI Ethernet module PHY address according your board schematic. + + config ETH_SPI_PHY_ADDR1 + depends on SPI_ETHERNETS_NUM > 1 + int "PHY Address of SPI Ethernet Module #2" + range 0 31 + default 1 + help + Set the second SPI Ethernet module PHY address according your board schematic. + endif # USE_SPI_ETHERNET + endif + endmenu + + + + menu "GPRS settings" + config WEBGUIAPP_GPRS_ENABLE + bool "Enabled GPRS PPP interface" + default n + help + Set enabled GPRS adapter + + if WEBGUIAPP_GPRS_ENABLE + + config WEBGUIAPP_GPRS_ON + bool "Default GPRS switched on" + default n + + config MODEM_DEVICE_POWER_CONTROL_PIN + int "Power control GPIO" + default -1 + range -1 33 + help + Pin number of power control. + + choice MODEM_DEVICE + prompt "Choose supported modem device (DCE)" + default MODEM_DEVICE_SIM800 + help + Select modem device connected to the ESP DTE. + config MODEM_DEVICE_SIM800 + bool "SIM800" + help + SIMCom SIM800L is a GSM/GPRS module. + It supports Quad-band 850/900/1800/1900MHz. + config MODEM_DEVICE_BG96 + bool "BG96" + help + Quectel BG96 is a series of LTE Cat M1/Cat NB1/EGPRS module. + config MODEM_DEVICE_SIM7600 + bool "SIM7600" + help + SIM7600 is Multi-Band LTE-TDD/LTE-FDD/HSPA+ and GSM/GPRS/EDGE module + endchoice + + config MODEM_PPP_APN + string "Set MODEM APN" + default "internet" + help + Set APN (Access Point Name), a logical name to choose data network + + config MODEM_PPP_AUTH_USERNAME + string "Set username for authentication" + default "gdata" + depends on !MODEM_PPP_AUTH_NONE + help + Set username for PPP Authentication. + + config MODEM_PPP_AUTH_PASSWORD + string "Set password for authentication" + default "gdata" + depends on !MODEM_PPP_AUTH_NONE + help + Set password for PPP Authentication. + + config MODEM_PPP_AUTH_NONE + bool "Skip PPP authentication" + default n + help + Set to true for the PPP client to skip authentication + + + config MODEM_NEED_SIM_PIN + bool "SIM PIN needed" + default n + help + Enable to set SIM PIN before starting the example + + config MODEM_SIM_PIN + string "Set SIM PIN" + default "1234" + depends on MODEM_NEED_SIM_PIN + help + Pin to unlock the SIM + + menu "UART Configuration" + config MODEM_UART_TX_PIN + int "TXD Pin Number" + default 17 + range 0 31 + help + Pin number of UART TX. + + config MODEM_UART_RX_PIN + int "RXD Pin Number" + default 16 + range 0 31 + help + Pin number of UART RX. + + config MODEM_UART_RTS_PIN + int "RTS Pin Number" + default 0 + range 0 31 + help + Pin number of UART RTS. + + config MODEM_UART_CTS_PIN + int "CTS Pin Number" + default 0 + range 0 31 + help + Pin number of UART CTS. + + config MODEM_UART_EVENT_TASK_STACK_SIZE + int "UART Event Task Stack Size" + range 2000 6000 + default 2048 + help + Stack size of UART event task. + + config MODEM_UART_EVENT_TASK_PRIORITY + int "UART Event Task Priority" + range 3 22 + default 5 + help + Priority of UART event task. + + config MODEM_UART_EVENT_QUEUE_SIZE + int "UART Event Queue Size" + range 10 40 + default 30 + help + Length of UART event queue. + + config MODEM_UART_PATTERN_QUEUE_SIZE + int "UART Pattern Queue Size" + range 10 40 + default 20 + help + Length of UART pattern queue. + + config MODEM_UART_TX_BUFFER_SIZE + int "UART TX Buffer Size" + range 256 2048 + default 512 + help + Buffer size of UART TX buffer. + + config MODEM_UART_RX_BUFFER_SIZE + int "UART RX Buffer Size" + range 256 2048 + default 1024 + help + Buffer size of UART RX buffer. + endmenu + + endif + endmenu + + menu "MQTT settings" + config WEBGUIAPP_MQTT_ENABLE + bool "Enabled MQTT transport" + default y + + if WEBGUIAPP_MQTT_ENABLE + config WEBGUIAPP_MQTT_CLIENTS_NUM + int "Number of MQTT clients" + range 1 2 + default 2 + + config WEBGUIAPP_MQTT_ON + bool "Enable MQTT client" + default y + + config WEBGUIAPP_MQTT_MAX_TOPIC_LENGTH + int "Max topic length" + range 32 512 + default 128 + + config WEBGUIAPP_MQTT_SERVER_URL + string "MQTT server URL" + default "myfirstmqttserver.com" + + config WEBGUIAPP_MQTT_SERVER_PORT + int "MQTT server port" + range 1 65535 + default 1883 + + config WEBGUIAPP_MQTT_CLIENT_ID_1 + string "MQTT_1 client ID prefix" + default "DEV1" + + if WEBGUIAPP_MQTT_CLIENTS_NUM > 1 + config WEBGUIAPP_MQTT_CLIENT_ID_2 + string "MQTT_2 client ID prefix" + default "DEV2" + endif + + config WEBGUIAPP_MQTT_SYSTEM_NAME + string "MQTT global system name" + default "SYSTEMNAME" + + config WEBGUIAPP_MQTT_GROUP_NAME + string "MQTT group name" + default "GROUPNAME" + + config WEBGUIAPP_MQTT_USERNAME + string "MQTT user name" + default "username" + + config WEBGUIAPP_MQTT_PASSWORD + string "MQTT user password" + default "password" + + endif + endmenu + + if WEBGUIAPP_WIFI_ENABLE || WEBGUIAPP_ETHERNET_ENABLE || WEBGUIAPP_GPRS_ENABLE + menu "DNS settings" + + config WEBGUIAPP_DNS1_ADDRESS_DEFAULT + string "DNS1" + default "8.8.8.8" + + config WEBGUIAPP_DNS2_ADDRESS_DEFAULT + string "DNS2" + default "8.8.4.4" + + config WEBGUIAPP_DNS3_ADDRESS_DEFAULT + string "DNS3" + default "1.1.1.1" + + endmenu + endif + endmenu \ No newline at end of file diff --git a/include/NetTransport.h b/include/NetTransport.h index e00755b..0f8ba5b 100644 --- a/include/NetTransport.h +++ b/include/NetTransport.h @@ -114,5 +114,6 @@ void StartSystemTimer(void); uint32_t GetUpTime(void); void RegEthReset(void (*eth_rst)(uint8_t level)); +void RegGSMReset(void (*gsm_rst)(uint8_t level)); #endif /* MAIN_INCLUDE_NETTRANSPORT_H_ */ diff --git a/src/GSMTransport.c b/src/GSMTransport.c index 80def1a..36676c1 100644 --- a/src/GSMTransport.c +++ b/src/GSMTransport.c @@ -1,277 +1,293 @@ - /* Copyright 2022 Bogdan Pilyugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * File name: GSMTransport.c - * Project: ChargePointMainboard - * Created on: 2022-07-21 - * Author: Bogdan Pilyugin - * Description: - */ - -#include -#include "freertos/FreeRTOS.h" -#include "freertos/event_groups.h" -#include "freertos/task.h" -#include "esp_netif.h" -#include "esp_netif_ppp.h" -#include "esp_event.h" -#include "esp_modem_api.h" -#include "esp_log.h" -#include "driver/gpio.h" -#include "SystemConfiguration.h" -#include "NetTransport.h" - - -#if CONFIG_WEBGUIAPP_GPRS_ENABLE -static EventGroupHandle_t event_group = NULL; -static const int CONNECT_BIT = BIT0; -static const char *TAG = "GSMTransport"; -static int ResetType = 0; -static bool isPPPinitializing = false; -#endif - -static bool isPPPConn = false; -TaskHandle_t initTaskhandle; - - -#define PPP_MODEM_TIMEOUT 40 - -MODEM_INFO mod_info = { "-", "-", "-", "-" }; -esp_netif_t *ppp_netif; -esp_modem_dce_t *dce; -TaskHandle_t trasporttask; - - - -esp_netif_t* GetPPPNetifAdapter(void) -{ - return ppp_netif; -} - -MODEM_INFO* GetPPPModemInfo(void) -{ - return &mod_info; -} - -bool isPPPConnected(void) -{ - return isPPPConn; -} - -#if CONFIG_WEBGUIAPP_GPRS_ENABLE -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 = event_data; - ESP_LOGI(TAG, "User interrupted event from netif:%p", netif); - } -} - -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, 0, &dns_info); - ESP_LOGI(TAG, "Name Server1: " IPSTR, IP2STR(&dns_info.ip.u_addr.ip4)); - esp_netif_get_dns_info(netif, 1, &dns_info); - ESP_LOGI(TAG, "Name Server2: " IPSTR, IP2STR(&dns_info.ip.u_addr.ip4)); - ESP_LOGI(TAG, "~~~~~~~~~~~~~~"); - xEventGroupSetBits(event_group, CONNECT_BIT); - isPPPConn = true; - ESP_LOGI(TAG, "GOT ip event!!!"); - } - else if (event_id == IP_EVENT_PPP_LOST_IP) - { - ESP_LOGI(TAG, "Modem Disconnect from PPP Server"); - isPPPConn = false; - } - 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)); - } -} - -void ModemNotReady(void) -{ - -} - -static void GSMInitTask(void *pvParameter) -{ - isPPPinitializing = true; - int starttype = *((int*) pvParameter); - esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, &on_ip_event); - esp_event_handler_unregister(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &on_ppp_changed); - - if (dce) - { - esp_modem_destroy(dce); - } - - if (ppp_netif != NULL) - { - esp_netif_destroy(ppp_netif); - } - - if (starttype == 0) - { - //SetGSM_PWR(OFF); - gpio_set_level(GPIO_NUM_2, 0); - vTaskDelay(pdMS_TO_TICKS(1000)); - //SetGSM_PWR(ON); - gpio_set_level(GPIO_NUM_2, 1); - } - 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(); - /* Configure 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.tx_io_num = CONFIG_MODEM_UART_TX_PIN; - dte_config.uart_config.rx_io_num = CONFIG_MODEM_UART_RX_PIN; - dte_config.uart_config.rts_io_num = CONFIG_MODEM_UART_RTS_PIN; - dte_config.uart_config.cts_io_num = CONFIG_MODEM_UART_CTS_PIN; - dte_config.uart_config.rx_buffer_size = CONFIG_MODEM_UART_RX_BUFFER_SIZE; - dte_config.uart_config.tx_buffer_size = CONFIG_MODEM_UART_TX_BUFFER_SIZE; - dte_config.uart_config.event_queue_size = CONFIG_MODEM_UART_EVENT_QUEUE_SIZE; - dte_config.task_stack_size = CONFIG_MODEM_UART_EVENT_TASK_STACK_SIZE; - dte_config.task_priority = CONFIG_MODEM_UART_EVENT_TASK_PRIORITY; - dte_config.dte_buffer_size = CONFIG_MODEM_UART_RX_BUFFER_SIZE / 2; - /* Configure the DCE */ - esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG(CONFIG_MODEM_PPP_APN); - /* Configure the PPP netif */ - esp_netif_inherent_config_t esp_netif_conf = ESP_NETIF_INHERENT_DEFAULT_PPP() - ; - esp_netif_conf.route_prio = PPP_PRIO; - esp_netif_config_t netif_ppp_config = ESP_NETIF_DEFAULT_PPP(); - - netif_ppp_config.base = &esp_netif_conf; - /* Init netif object */ - ppp_netif = esp_netif_new(&netif_ppp_config); - assert(ppp_netif); - dce = esp_modem_new_dev(ESP_MODEM_DCE_SIM800, &dte_config, &dce_config, ppp_netif); - assert(dce); - - mod_info.model[0] = 0x00; - int GSMConnectTimeout = 0; - while (esp_modem_get_module_name(dce, mod_info.model) != ESP_OK) - { - if (++GSMConnectTimeout >= PPP_MODEM_TIMEOUT) - goto modem_init_fail; - vTaskDelay(pdMS_TO_TICKS(1000)); - } - ESP_LOGI(TAG, "Module type:%s", mod_info.model); - - mod_info.imsi[0] = 0x00; - while (esp_modem_get_imsi(dce, mod_info.imsi) != ESP_OK) - { - if (++GSMConnectTimeout >= PPP_MODEM_TIMEOUT) - goto modem_init_fail; - vTaskDelay(pdMS_TO_TICKS(1000)); - } - ESP_LOGI(TAG, "IMSI:%s", mod_info.imsi); - - mod_info.oper[0] = 0x00; int tech = 0; - while (esp_modem_get_operator_name(dce, mod_info.oper, &tech) != ESP_OK) - { - if (++GSMConnectTimeout >= PPP_MODEM_TIMEOUT) - goto modem_init_fail; - vTaskDelay(pdMS_TO_TICKS(1000)); - } - ESP_LOGI(TAG, "Operator:%s", mod_info.oper); - - mod_info.imei[0] = 0x00; - while (esp_modem_get_imei(dce, mod_info.imei) != ESP_OK) - { - if (++GSMConnectTimeout >= PPP_MODEM_TIMEOUT) - goto modem_init_fail; - vTaskDelay(pdMS_TO_TICKS(1000)); - } - ESP_LOGI(TAG, "IMEI:%s", mod_info.imei); - - while (esp_modem_set_mode(dce, ESP_MODEM_MODE_DATA) != ESP_OK) - { - if (++GSMConnectTimeout >= PPP_MODEM_TIMEOUT) - goto modem_init_fail; - vTaskDelay(pdMS_TO_TICKS(1000)); - } - - ESP_LOGI(TAG, "PPP data mode OK"); - - xEventGroupWaitBits(event_group, CONNECT_BIT, pdTRUE, pdTRUE, portMAX_DELAY); - - isPPPinitializing = false; - vTaskDelete(NULL); - - return; -modem_init_fail: - ESP_LOGE(TAG, "PPP modem init error"); - isPPPinitializing = false; - vTaskDelete(NULL); -} - -void PPPModemColdStart(void) -{ - ResetType = 0; - xTaskCreate(GSMInitTask, "GSMInitTask", 1024 * 4, &ResetType, 3, initTaskhandle); -} - -void PPPModemSoftRestart(void) -{ - ResetType = 1; - xTaskCreate(GSMInitTask, "GSMInitTask", 1024 * 4, &ResetType, 3, initTaskhandle); -} - -static void GSMRunTask(void *pvParameter) -{ - while (1) - { - if (!isPPPConn && !isPPPinitializing) - { //try to reconnect modem - ESP_LOGI(TAG, "PPP modem restart"); - PPPModemColdStart(); - } - vTaskDelay(pdMS_TO_TICKS(30000)); - } -} - -void PPPModemStart(void) -{ - xTaskCreate(GSMRunTask, "GSMRunTask", 1024 * 4, &ResetType, 3, NULL); -} - -#endif - - - +/* Copyright 2022 Bogdan Pilyugin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * File name: GSMTransport.c + * Project: ChargePointMainboard + * Created on: 2022-07-21 + * Author: Bogdan Pilyugin + * Description: + */ + +#include +#include "freertos/FreeRTOS.h" +#include "freertos/event_groups.h" +#include "freertos/task.h" +#include "esp_netif.h" +#include "esp_netif_ppp.h" +#include "esp_event.h" +#include "esp_modem_api.h" +#include "esp_log.h" +#include "driver/gpio.h" +#include "SystemConfiguration.h" +#include "NetTransport.h" + +#if CONFIG_WEBGUIAPP_GPRS_ENABLE +static EventGroupHandle_t event_group = NULL; +static const int CONNECT_BIT = BIT0; +static const char *TAG = "GSMTransport"; +static int ResetType = 0; +static bool isPPPinitializing = false; +#endif + +static bool isPPPConn = false; +TaskHandle_t initTaskhandle; + +#define PPP_MODEM_TIMEOUT 40 + +MODEM_INFO mod_info = { "-", "-", "-", "-" }; +esp_netif_t *ppp_netif; +esp_modem_dce_t *dce; +TaskHandle_t trasporttask; + +static void (*gsm_reset)(uint8_t level) = NULL; +void RegGSMReset(void (*gsm_rst)(uint8_t level)) +{ + gsm_reset = gsm_rst; +} + +esp_netif_t* GetPPPNetifAdapter(void) +{ + return ppp_netif; +} + +MODEM_INFO* GetPPPModemInfo(void) +{ + return &mod_info; +} + +bool isPPPConnected(void) +{ + return isPPPConn; +} + +#if CONFIG_WEBGUIAPP_GPRS_ENABLE +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 = event_data; + ESP_LOGI(TAG, "User interrupted event from netif:%p", netif); + } +} + +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, 0, &dns_info); + ESP_LOGI(TAG, "Name Server1: " IPSTR, IP2STR(&dns_info.ip.u_addr.ip4)); + esp_netif_get_dns_info(netif, 1, &dns_info); + ESP_LOGI(TAG, "Name Server2: " IPSTR, IP2STR(&dns_info.ip.u_addr.ip4)); + ESP_LOGI(TAG, "~~~~~~~~~~~~~~"); + xEventGroupSetBits(event_group, CONNECT_BIT); + isPPPConn = true; + ESP_LOGI(TAG, "GOT ip event!!!"); + } + else if (event_id == IP_EVENT_PPP_LOST_IP) + { + ESP_LOGI(TAG, "Modem Disconnect from PPP Server"); + isPPPConn = false; + } + 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)); + } +} + +void ModemNotReady(void) +{ + +} + +static void GSMInitTask(void *pvParameter) +{ + isPPPinitializing = true; + int starttype = *((int*) pvParameter); + esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, &on_ip_event); + esp_event_handler_unregister(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &on_ppp_changed); + + if (dce) + { + esp_modem_destroy(dce); + } + + if (ppp_netif != NULL) + { + esp_netif_destroy(ppp_netif); + } + + if (starttype == 0) + { +#if CONFIG_MODEM_DEVICE_POWER_CONTROL_PIN >= 0 + gpio_set_level(CONFIG_MODEM_DEVICE_POWER_CONTROL_PIN, 0); + vTaskDelay(pdMS_TO_TICKS(1000)); + gpio_set_level(CONFIG_MODEM_DEVICE_POWER_CONTROL_PIN, 1); +#else + if (gsm_reset) + { + gsm_reset(0); + vTaskDelay(pdMS_TO_TICKS(1000)); + gsm_reset(1); + vTaskDelay(pdMS_TO_TICKS(10000)); + } + else + { + ESP_LOGE(TAG, "ethernet chip reset pin not defined"); + ESP_ERROR_CHECK(1); + } +#endif + + } + + 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(); + /* Configure 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.tx_io_num = CONFIG_MODEM_UART_TX_PIN; + dte_config.uart_config.rx_io_num = CONFIG_MODEM_UART_RX_PIN; + dte_config.uart_config.rts_io_num = CONFIG_MODEM_UART_RTS_PIN; + dte_config.uart_config.cts_io_num = CONFIG_MODEM_UART_CTS_PIN; + dte_config.uart_config.rx_buffer_size = CONFIG_MODEM_UART_RX_BUFFER_SIZE; + dte_config.uart_config.tx_buffer_size = CONFIG_MODEM_UART_TX_BUFFER_SIZE; + dte_config.uart_config.event_queue_size = CONFIG_MODEM_UART_EVENT_QUEUE_SIZE; + dte_config.task_stack_size = CONFIG_MODEM_UART_EVENT_TASK_STACK_SIZE; + dte_config.task_priority = CONFIG_MODEM_UART_EVENT_TASK_PRIORITY; + dte_config.dte_buffer_size = CONFIG_MODEM_UART_RX_BUFFER_SIZE / 2; + /* Configure the DCE */ + esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG(CONFIG_MODEM_PPP_APN); + /* Configure the PPP netif */ + esp_netif_inherent_config_t esp_netif_conf = ESP_NETIF_INHERENT_DEFAULT_PPP(); + + esp_netif_conf.route_prio = PPP_PRIO; + esp_netif_config_t netif_ppp_config = ESP_NETIF_DEFAULT_PPP(); + + netif_ppp_config.base = &esp_netif_conf; + /* Init netif object */ + ppp_netif = esp_netif_new(&netif_ppp_config); + assert(ppp_netif); + dce = esp_modem_new_dev(ESP_MODEM_DCE_SIM800, &dte_config, &dce_config, ppp_netif); + assert(dce); + + mod_info.model[0] = 0x00; + int GSMConnectTimeout = 0; + while (esp_modem_get_module_name(dce, mod_info.model) != ESP_OK) + { + if (++GSMConnectTimeout >= PPP_MODEM_TIMEOUT) + goto modem_init_fail; + vTaskDelay(pdMS_TO_TICKS(1000)); + } + ESP_LOGI(TAG, "Module type:%s", mod_info.model); + + mod_info.imsi[0] = 0x00; + while (esp_modem_get_imsi(dce, mod_info.imsi) != ESP_OK) + { + if (++GSMConnectTimeout >= PPP_MODEM_TIMEOUT) + goto modem_init_fail; + vTaskDelay(pdMS_TO_TICKS(1000)); + } + ESP_LOGI(TAG, "IMSI:%s", mod_info.imsi); + + mod_info.oper[0] = 0x00; + int tech = 0; + while (esp_modem_get_operator_name(dce, mod_info.oper, &tech) != ESP_OK) + { + if (++GSMConnectTimeout >= PPP_MODEM_TIMEOUT) + goto modem_init_fail; + vTaskDelay(pdMS_TO_TICKS(1000)); + } + ESP_LOGI(TAG, "Operator:%s", mod_info.oper); + + mod_info.imei[0] = 0x00; + while (esp_modem_get_imei(dce, mod_info.imei) != ESP_OK) + { + if (++GSMConnectTimeout >= PPP_MODEM_TIMEOUT) + goto modem_init_fail; + vTaskDelay(pdMS_TO_TICKS(1000)); + } + ESP_LOGI(TAG, "IMEI:%s", mod_info.imei); + + while (esp_modem_set_mode(dce, ESP_MODEM_MODE_DATA) != ESP_OK) + { + if (++GSMConnectTimeout >= PPP_MODEM_TIMEOUT) + goto modem_init_fail; + vTaskDelay(pdMS_TO_TICKS(1000)); + } + + ESP_LOGI(TAG, "PPP data mode OK"); + + xEventGroupWaitBits(event_group, CONNECT_BIT, pdTRUE, pdTRUE, portMAX_DELAY); + + isPPPinitializing = false; + vTaskDelete(NULL); + + return; +modem_init_fail: + ESP_LOGE(TAG, "PPP modem init error"); + isPPPinitializing = false; + vTaskDelete(NULL); +} + +void PPPModemColdStart(void) +{ + ResetType = 0; + xTaskCreate(GSMInitTask, "GSMInitTask", 1024 * 4, &ResetType, 3, initTaskhandle); +} + +void PPPModemSoftRestart(void) +{ + ResetType = 1; + xTaskCreate(GSMInitTask, "GSMInitTask", 1024 * 4, &ResetType, 3, initTaskhandle); +} + +static void GSMRunTask(void *pvParameter) +{ + while (1) + { + if (!isPPPConn && !isPPPinitializing) + { //try to reconnect modem + ESP_LOGI(TAG, "PPP modem restart"); + PPPModemColdStart(); + } + vTaskDelay(pdMS_TO_TICKS(30000)); + } +} + +void PPPModemStart(void) +{ + xTaskCreate(GSMRunTask, "GSMRunTask", 1024 * 4, &ResetType, 3, NULL); +} + +#endif +