We have moved to a new Sailfish OS Forum. Please start new discussions there.
26

[HowTo]: Script to enable tethering (hotspot) on SailfishX

asked 2017-10-19 01:17:14 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

updated 2017-10-19 01:18:04 +0200

joschobart gravatar image

As tethering is a needed prerequisite for me to use my JollaX as a daily driver, I've tinkered this tiny script based on this zendesk-article: https://jolla.zendesk.com/hc/en-us/articles/115013777068 Feel free to use it yourself or to improve it! (This is a Wiki-Article)

#!/bin/bash

if [ "$EUID" -ne 0 ]
  then echo "Please run as root (type devel-su first)"
  exit 1
fi

if [[ $1 == "off" ]]; then
  echo "Best way to turn off hotspot at the moment is restarting your device..."
  exit 0
elif [[ $1 == "on" ]]; then
  echo "Switch Tethering ON.."
  echo 2 > /sys/module/bcmdhd/parameters/op_mode
  sleep 1
  echo "Now restart WLAN from UI (\"Settings > WLAN\") and enable hotspot (\"Settings > Internet sharing\")"
  read -p "Done with the instruction above? Then press [Enter] to continue..."
  ip link set dev wlan0 master tether
  sleep 1
  echo "Enjoy tethering on your Xperia X!;)"
  exit 0
else
  echo "USAGE: $0 <on><off>"
  exit 1
fi
edit retag flag offensive close delete

Comments

1

Nice, thank you. But why do you have to restart to turn it off? Does echo 1 > /sys/module/bcmdhd/parameters/op_mode not work?

Sokinama ( 2017-10-20 20:24:15 +0200 )edit

hey Sokinama! Disable tethering as in your suggestion lead to problems reconnecting to known wlan networks in my case. had no time so far to digg deeper, but feel free to improve if you can help!;)

joschobart ( 2017-10-23 23:58:56 +0200 )edit
2

For the 'noobs' with us, you have to put it in a file with the extension filename.sh and start it with 'bash filename.sh on' for on and for off 'bash filename.sh off'. Coming from windows, costs a small hour to find out ;)

Can anybody tell me how coding tags are working on this forum, it's not mentioned in the help of this site.....

Tethering works now fine for me. Before I used tethering over USB.

Gatze ( 2017-10-27 19:08:27 +0200 )edit
1

thanks for the script, it works well. thinking about getting it to turn off too, I presume if we restart networking after setting echo 1 > /sys/module/bcmdhd/parameters/op_mode, hopefully it should work. I'm not sure what the low level network restart command is, but will look into it. I guess if it was that easy they would have implemented it by now though...

zepher ( 2017-11-09 16:46:48 +0200 )edit

3 Answers

Sort by » oldest newest most voted
5

answered 2017-12-05 22:45:00 +0200

Phil_ gravatar image

I used this command pkcon install connman-tools to install connman. Then I use a script to activate the hotspot:


screen -d -m -S hotspot
screen -S hotspot -p 0 -X stuff "devel-su
"
sleep 0.8
screen -S hotspot -p 0 -X stuff "*ROOT*PW*
"
sleep 0.2
screen -S hotspot -p 0 -X stuff "echo 2 > /sys/module/bcmdhd/parameters/op_mode
"
sleep 0.2
screen -S hotspot -p 0 -X stuff "connmanctl disable wifi
"
sleep 0.2
screen -S hotspot -p 0 -X stuff "connmanctl enable wifi
"
sleep 0.2
connmanctl tether wifi on
sleep 1
screen -S hotspot -p 0 -X stuff "ip link set dev wlan0 master tether
"

It does all the steps without further actions in the GUI.

To deactivate the hotspot I use:


screen -S hotspot -p 0 -X stuff "echo 1 > /sys/module/bcmdhd/parameters/op_mode
"
sleep 0.1
connmanctl tether wifi off
screen -S hotspot -p 0 -X stuff "connmanctl disable wifi
"
sleep 0.2
screen -S hotspot -p 0 -X stuff "connmanctl enable wifi
"
sleep 0.2
screen -S hotspot -p 0 -X stuff "exit
"
sleep 0.1
screen -S hotspot -p 0 -X stuff "exit
"
edit flag offensive delete publish link more

Comments

4

Jolla should be able to do this in the GUI, a trainee can do that. :(

Moo-Crumpus ( 2017-12-06 16:51:41 +0200 )edit

nice, thanks for sharing! I'll give that a try later

joschobart ( 2017-12-06 18:36:57 +0200 )edit

Hi,

when I use these scripts I have to re-enter the WPA password for my network each tim after disabling the hotspot, so the phone does not automatically reconnect to ma network. The network is then shown multiple times in the WLAN settings - once for each time I disabled tethering.

Edit: Found it! Instead of disabling and enabling wifi after setting op_mode to 1, use systemctl restart wpa_supplicant.service and systemctl restart connman.service. This enables reconnection to the WiFi network without issues.

I use the situations app to start these commands - so you can start tethering via GUI instead of CLI.

tmichel ( 2017-12-07 00:37:17 +0200 )edit

bash 3.2 seems to support $'dollar-single'. all these that require newlines could be written like e.g. $'exit\n'

too ( 2017-12-07 09:21:53 +0200 )edit
2

answered 2017-12-06 18:12:48 +0200

Chap gravatar image

Hello I would really, really have some tethering on my Xperia. But I am a noob...

Where do I put the file ? How can I invoke the script ? How do I run the terminal on the phone ?

Thank you for your help !

edit flag offensive delete publish link more

Comments

2

Hey Chap! To use the terminal you have to activate the developer-mode in the settings. Once you've done that activate remote connection and set a password, that's done in the developer-mode options in settings too. Next open the terminal app from the app grid and type 'devel-su' (it will ask for the password you've just set). You have a root shell now. Type 'nano tethering.sh' and type in the code. Once you've finished, save the file and exit. Now make the new file executable by typing 'chmod ug+x tethering.sh'. To run the script type './tethering.sh'. That's it. Hope it helps! otherwise google for basic bash commands. Of course via SSH it would be much easier. Search for SSH here on tjc for more about that.

joschobart ( 2017-12-06 18:36:12 +0200 )edit
2

Thanks a lot joschobart ! That is exactly what I was searching for. I'd rather edit the file on a Pc and transfert it via USB, the rest will be just fine.

Great to be able to use the phone as a modem again. (Still missing a good camera treatment...)

Chap ( 2017-12-06 20:41:17 +0200 )edit
0

answered 2017-12-05 21:43:49 +0200

TomC gravatar image

updated 2017-12-05 22:33:53 +0200

Why do you need to disable with echo 1 > /sys/module/bcmdhd/parameters/op_mode?

Can we expect problems if we only disable by turning hotspot off in UI and then enable again with ip link..., without changing ...op_code in between?

edit flag offensive delete publish link more
Login/Signup to Answer

Question tools

Follow
14 followers

Stats

Asked: 2017-10-19 01:17:14 +0200

Seen: 2,351 times

Last updated: Dec 06 '17