micropython / micropython-esp32

Old port of MicroPython to the ESP32 -- new port is at https://github.com/micropython/micropython
MIT License
680 stars 219 forks source link

LAN function issue #253

Closed hetvishah08 closed 5 years ago

hetvishah08 commented 5 years ago

I am developing an application with ESP32 DevkitC and LAN8720 where using ModbusTCP i am trying to read the holding registers.I want to connect whenever needed and then disconnected it.I am facing an issue here when i use:

Code:

from machine import Pin from machine import UART from time import sleep import network from uModBusTCP import uModBusTCP as TCP

def lan_config():

l = network.LAN() l.init(mdc = Pin(23), mdio = Pin(18), power = Pin(17), phy_type = network.PHY_LAN8720, phy_addr=1) l.ifconfig() l.active(1) m = l.ifconfig() print(m)

while True: lan_config() modbus=TCP('192.168.29.53', 502, 60) print(modbus.read_holding_registers(1, 0, 2,True)) print(modbus.write_single_register(1, 4, 101, True)) print('hello') modbus.close() l.deinit() sleep(5)

I get debug messages as following:

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:0x3fff0018,len:4 load:0x3fff001c,len:4732 load:0x40078000,len:7496 load:0x40080400,len:5512 entry 0x4008114c I (399) cpu_start: Pro cpu up. I (399) cpu_start: Single core mode I (400) heap_init: Initializing. RAM available for dynamic allocation: I (403) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM I (409) heap_init: At 3FFC0E00 len 0001F200 (124 KiB): DRAM I (415) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM I (422) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM I (428) heap_init: At 400915E0 len 0000EA20 (58 KiB): IRAM I (434) cpu_start: Pro cpu start user code I (5) cpu_start: Starting scheduler on PRO CPU. I (532) modsocket: Initializing Traceback (most recent call last): File "main.py", line 19, in File "main.py", line 11, in lan_config TypeError: 'mdc' argument required MicroPython v1.9.4-761-g7cd59c5bc on 2018-12-27; ESP32 module with ESP32 Type "help()" for more information.

When I changed my code to this it works fine but then i cannot shut the LAN:

from machine import Pin from machine import UART from time import sleep import network from uModBusTCP import uModBusTCP as TCP

def lan_config():

l = network.LAN(mdc = Pin(23), mdio = Pin(18), power = Pin(17), phy_type = network.PHY_LAN8720, phy_addr=1) l.ifconfig() l.active(1) m = l.ifconfig() print(m)

while True: lan_config() modbus=TCP('192.168.29.53', 502, 60) print(modbus.read_holding_registers(1, 0, 2,True)) print(modbus.write_single_register(1, 4, 101, True)) print('hello') modbus.close() sleep(5)

Debug Messages: After every 5 seconds

('192.168.29.71', '255.255.255.0', '192.168.29.1', '192.168.29.1') (0, 0) True hello

Also after reset my code hangs at LAN settings:

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:0x3fff0018,len:4 load:0x3fff001c,len:4732 load:0x40078000,len:7496 load:0x40080400,len:5512 entry 0x4008114c I (399) cpu_start: Pro cpu up. I (399) cpu_start: Single core mode I (400) heap_init: Initializing. RAM available for dynamic allocation: I (403) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM I (409) heap_init: At 3FFC0E00 len 0001F200 (124 KiB): DRAM I (415) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM I (422) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM I (428) heap_init: At 400915E0 len 0000EA20 (58 KiB): IRAM I (434) cpu_start: Pro cpu start user code I (5) cpu_start: Starting scheduler on PRO CPU. I (531) modsocket: Initializing I (541) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE I (541) emac: emac start !!!

I (541) emac: emac resetting .... I (541) emac: emac reset done I (561) emac: emac start success !!! I (561) network: event 20 ('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0') File "main.py", line 19, in OSError: 118 MicroPython v1.9.4-761-g7cd59c5bc on 2018-12-27; ESP32 module with ESP32 Type "help()" for more information.

I (4561) emac: eth link_up!!! I (4561) network: event 22 I (5321) event: eth ip: 192.168.29.71, mask: 255.255.255.0, gw: 192.168.29.1 I (5321) network: event 24

After this the code doesn't run and is stuck here.