RP2040 as network guard

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
Kevig
Posts: 3
Joined: Thu May 12, 2022 5:57 pm

RP2040 as network guard

Post by Kevig » Thu May 12, 2022 6:18 pm

hello,
first of all, i am a complete noob on the RP2040, python and micro python.

I want to use the arduina RP2040connect as a network guard.
it should check if a PC is online and then start the serverpc.

for that i need to ping the pc(s) and see if they are online.
I got this so far, but i get a error module object has no attribute system
what am i doing wrong?
grtz henk

import network, os


SSID='***' # Network SSID
KEY='********' # Network key

# Init wlan module and connect to network
print("Trying to connect... (may take a while)...")

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK)
print(wlan.ifconfig())


hostname = "192.***.***.**"
response = os.system("ping -c 1 " + hostname)
if response == 0:
pingstatus = "Network Active"
else:
pingstatus = "Network Error"

module object has no attribute system

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: RP2040 as network guard

Post by Roberthh » Thu May 12, 2022 6:27 pm

There is no os.system() method, since there is no underlying OS like Linux or Windows.
For Ping, there is a script called uping(). But that does not work yet on a RP2040.

Kevig
Posts: 3
Joined: Thu May 12, 2022 5:57 pm

Re: RP2040 as network guard

Post by Kevig » Fri May 13, 2022 8:37 am

thank you for the fast response.

so i have a problem, no ping = no network guard = no RP2040

so now i have two possible ways ahead:

try it with the rpi zero 2 w or try to adapt the uping() script

can you tell me where i can find the uping() script?

rgrds
henk

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: RP2040 as network guard

Post by Roberthh » Fri May 13, 2022 9:06 am

The uping script is at https://gist.github.com/91cc8979e33e82a ... 8195fb.git

The problem is, that at the moment the NINA firmware used by the RP2040 does not support the socket RAW mode. There is work in progress to fix that. See https://github.com/micropython/micropython/pull/8654.
I did not test it yet with uping, but I plan to do than the next days.

You might use other ways to test the PC for presence, like doing a socket connect to a service that should exist on that device.

Kevig
Posts: 3
Joined: Thu May 12, 2022 5:57 pm

Re: RP2040 as network guard

Post by Kevig » Fri May 13, 2022 10:31 am

thanks,

i have no clue how even to start the socket thing, and i have to ping 8 different win computers.
so i think i keep an eye out for the nina upgrade.
it gives me also time to figure out how to use the uping() script.
i think i need to put the github file in the root of the RP4060 and then in my file use the import function and call the script

for the time being i use the pi zero, that way my network will shut down and startup like i want it.
and it gives me the the tome to get more aquainted with pytho/microphyton

rgrds
henk

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: RP2040 as network guard

Post by Roberthh » Fri May 13, 2022 1:54 pm

it gives me also time to figure out how to use the uping() script.
Yup. Once you have put it on the RP2040, you can run:

import uping
uping.ping(<ip-address, quiet=True | False, ...>

It has a few more options. It tries a few times, and then it returns a 2 element tuple with the pass/fail values,

Post Reply