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.

P.S: Don't tell me to leave the IP as it is and similar suggestions.

I have:
Raspberry Pi 3B+ with official power supply
Sandisk Class 10 SD card with Raspbian Stretch full

If you do not know any programming language, Python is a good start. If you actually are fluent in any other programming language, why don't you use it on the Pi ? Chances are it works already.

ghans

• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

If you do not know any programming language, Python is a good start. If you actually are fluent in any other programming language, why don't you use it on the Pi ? Chances are it works already.

ghans

Consider me absolute beginner, even though I might know C, C++ and Java, my knowledge of them is equivalent to knowing the alphabets. I can't figure out how to do what I want with those languages, so I'm asking here. What specific libraries will help me? It also seems to require me to know the Linux system APIs, command line to accomplish this.

Can you point me to specific programming languages which allow me to accomplish that in as short a time as possible?

Last edited by shrewdgamer on Fri May 03, 2019 11:13 am, edited 1 time in total.

I have:
Raspberry Pi 3B+ with official power supply
Sandisk Class 10 SD card with Raspbian Stretch full

You said you want some user input for a time interval and then to alternately connect to two wireless networks. It's very doable in shell. POSIX is the least common denominator variant and the most portable.

You said you want some user input for a time interval and then to alternately connect to two wireless networks. It's very doable in shell. POSIX is the least common denominator variant and the most portable.

Ruby is the way to go. Although python is similar, I find it more glitchy and buggy than Ruby.

Ruby also requires less code to do the same thing. It's easy to use and easy to learn.

Python really is over rated, and it's interpreter can be more touchy than Java, c#, etc. Plus Ruby has tons of resources and can be used with any kind of programming language and on any kind of operating system. Meaning the code you write on your pi will work on Windows and Mac without any special cross platform coding.

Ruby on rails is it's web development, and the most popular use of Ruby (Twitter started out as a purely RoR), and without Ruby the "hashtag" would not exist.

Now for this project you will also need to read up on the CLI commands, or the bash shell that the kernel uses. With Ruby, you can not just modify the CLI commands, but completely create your own custom commands.

This second code with system works just like the first with the back ticks. However I added another line with puts. The puts(put to string) will display the output and always on a new line. The print command does the same without starting a new line. In this second example, when you call your command it will look as such....

IRB>cpu0_temp
59 °C
Nil
IRB>

This is very useful because now we can pull up the CPU temp anytime we call that def, we can now manipulate the data however we want like so....

3.times do
Time.now
Cpu0_temp
sleep(1)
end

This will output

13:00:00
49°C
13:00:01
48°C
13:00:02
52°c

So how can we use this data to control our pi? Let's say we want the pi to shut itself off if the core reaches dangerous temps. With our cpu0_temp command this is very easy to do.

Let's make a new definition.

def check_cpu0(without the puts code)
loop do
cpu0_temp
sleep (1)
end

This will tell the pi to run our new command once every second and stores it within bthis def. The second part of this will be the if statement

If check_cpu0 == 80°C
`sudo shutdown -h`.chomp
end

Now that we have our script made, we want the pi to run it when it boots, so now we have to edit the .rc_local file.
We want to use the .rc_local file over the .bash_aliases because .rc_local runs anything at BOOT and .bash_aliases starts scripts when the User log in level.

Now we need to add the line
ruby File/path/to/script/pi_overheat_protect.rb &

The & is VERY Important because it tells the pi to run our script as a background process.

It's that easy.

You can use this same concept for your script. It will work the same way.

Last edited by Rabbit_Pi on Fri May 03, 2019 7:45 pm, edited 1 time in total.

Shortest path:
- use wpa-cli from bash to control wpa_supplicant,
- create a systemd unit service to start your script,
- provide a systemd config file the user can edit,
- hit a geoip provider from the script, that will return the public IP and the assumed location of the router used by the AP.