davesteele / comitup

Bootstrap Wifi support over Wifi
https://davesteele.github.io/comitup/
GNU General Public License v2.0
322 stars 54 forks source link

Question: Best way to execute python code after raspberry pi has connected to router? #213

Closed gbernal closed 2 years ago

gbernal commented 2 years ago

Dear @davesteele,

Thank you first of all for sharing your work. I'm using comitup for a research project on a raspberry pi 3B. I have a python script that sends over WebSockets the device IP every time the pi is connected to the new user's local router so I can then ssh into the device without having to connect to a monitor.

I have seen at StackOverflow that people suggest putting the python code here "/etc/network/if-up.d/upstart" just after "all_interfaces_up" https://stackoverflow.com/questions/29204423/how-to-automatically-run-python-script-after-raspberry-pi-fully-boots

But since the network interface is handled by comitup I figured it might be better to ask here how to go about. (The upstart file is no longer in the location suggested in stackoverflow.)

Thank you in advance.

davesteele commented 2 years ago
  1. Comitup publishes the ip address on all interfaces. If you have mdns support, just attempt "ssh comitup@<service_name>.local. The service_name is the name used for the SSID in HOTSPOT mode.
  2. If you place an executable script at /usr/local/bin/comitup-callback, it will be called with the first argument = "CONNECTED" when the upstream connection is successful. See the external_callback parameter on the comitup.conf man page.
  3. Use comitup-watch to discover IP addresses of connected Comitup devices.
gbernal commented 2 years ago

Wonderful! Thank you @davesteele!

gbernal commented 2 years ago

Dear @davesteele

One more question, can you please clarify what does comitup-callback mean in this path ?/usr/local/bin/comitup-callback. Is comitup-callback my script or a directory? My RPi only had usr/local/bin/ but nothing after that. Is that a path I have to create?

Screen Shot 2022-07-26 at 4 18 18 PM

Also, Am I right to assume that I have to modify comitup.conf from # external_callback: /usr/local/bin/comitup-callback to external_callback: /usr/local/bin/comitup-callback/myscript.py ?

Thank you again.

davesteele commented 2 years ago

comitup-callback is an executable script that is your responsibility. The path is defined by the external_callback parameter, but, if you don't define that parameter, it takes the value shown in the comitup.conf comment. So, no, you don't have to make that change.