0

I want to run a program or script on Raspberry Pi 3B+, which allows the user to set an amount of time for it to connect to WiFi 1, after the expiry of that time it has to connect another WiFi 2 for another amount of time, after the expiry of this, connect to WiFi 1 again, like this it should keep connecting in cycles.

While connected to these WiFis, it should check every few minutes(which I can set) at a site which gives information about the IP address, and if the location of IP shows a particular area's name, it should reboot the router, to obtain a new IP. This should start on Raspbian boot.

What programming languages and knowledge do I need to learn to accomplish the above task.

Thanks for your valuable suggestions.

  • 2
    your question is not related to RPi ..... it is a linux question, so you may have better luck asking at a linux site ........ check this out .... https://www.linuxquestions.org/questions/linux-general-1/wifi-connect-script-tested-in-ubuntu-772646/ – jsotola May 02 '19 at 21:25
  • this is unclear ... it should reboot the router, to obtain a new IP – jsotola May 02 '19 at 21:26
  • @jsotola The script should keep checking at a site which shows information about the IP, if the IP has a particular location, the script should reboot the router, so that it'll get a new IP. The router gets a new IP if it's rebooted. – ShrewdGamer May 02 '19 at 21:30
  • why are you repeating what you already said in your question? ..... how do you plan to reboot the router? – jsotola May 02 '19 at 21:35
  • @jsotola I don't know, it has a web interface, which I can log into and reboot from the management section. It might take HTML requests and perform the reboot? Do you think it's possible? – ShrewdGamer May 02 '19 at 23:46
  • Why would a new IP after a reboot suddenly be from a different area? – RalfFriedl May 03 '19 at 05:23
  • @RalfFriedl Sometime it gets a new IP. – ShrewdGamer May 03 '19 at 11:45
  • I re-read you post and it is beginning to make no sense .... the router IP is obtained from the ISP .... why do you think that the ISP would give you an IP address that is on a different subnet ..... did you provide all of the information? – jsotola May 03 '19 at 23:20

1 Answers1

1

Your question is mostly a general programming issue. You should better ask on one of our sister sites for programming. But here is a suggestion to the Raspberry Pi part for using its WiFi interface and selecting networks.

First you define the networks you want to connect to within /etc/wpa_supplicant/wpa_supplicant.conf. The first network block has index number 0, the second has 1 and so on. Now you can use wpa_cli to select a network and connect to it. How to do it you can google, for example How to connect to a network using wpa_cli. The commands given there can also be executed on the command line so you can call them within the programming language you want to use. Using bash the examples would look like this. You should run them with root rights:

rpi ~# wpa_cli -i wlan0 add_network
rpi ~# wpa_cli -i wlan0 set_network 0 ssid "MYNETWORK"
rpi ~# wpa_cli -i wlan0 set_network 0 psk "secret"
rpi ~# wpa_cli -i wlan0 enable_network 0

This commands should also be executable by calls from a programming language.

Ingo
  • 42,107
  • 20
  • 85
  • 197