Skip to content

Instantly share code, notes, and snippets.

@Bobtron
Forked from Arttumiro/gps.xhtml
Last active October 15, 2023 02:12
Show Gist options
  • Save Bobtron/831dfcde677b529c6224cb52bdb177e5 to your computer and use it in GitHub Desktop.
Save Bobtron/831dfcde677b529c6224cb52bdb177e5 to your computer and use it in GitHub Desktop.
PAW-gps Mobile code+application
Originally from: https://raw.githubusercontent.com/systemik/pwnagotchi-bt-tether/master/GPS-via-PAW
Systemik made the original code and shaynemk on the pwnagotchi boards added timestamps, altitude, and satellites to the code
You can follow the original guide if you want, this one is just using a bit different code and is typed out a bit better
This is just the android part of the whole guide but the rest can be found here https://community.pwnagotchi.ai/t/setting-up-paw-gps-on-android
And just so everyone knows, me (Arttumiro) didnt do anything coding related at all, i just changed up the guide a bit and made it easier to follow.
======================================================================================
Site of the app I use : http://paw-android.fun2code.de (It needs a lot of permissions but it will not do anything automatically)
Dont worry about incompatibility warnings, the gps code should still work even with that.
Downloading the app and pressing the button to start it should be all you need to do on the app itself.
Then you create the file to allow the pwnagotchi to retrieve gps data.
Create a file in the internal storage /paw/html folder on your phone called gps.xhtml
Systemik (the original author) used Mixplorer and that seems to work well. Any other file file explorer should still work.
Copy and paste everything from <bsh> to </bsh> down below and paste it into the file
(You might need to name it gps.txt first, paste and save the code, and then rename it back to gps.xhtml)
(Code with no timestamps can be found here https://raw.githubusercontent.com/systemik/pwnagotchi-bt-tether/master/GPS-via-PAW)
(Warning, the old code wont work with webgpsmap plugin ^^)
(Start copying from under this text, so from line 22 to the end)
======================================================================================
For some reason, the original script written here, and with the text above
https://gist.github.com/Arttumiro/d359769bc492559fe3098ac890a3c807
didn't work on my Samsung Galaxy S6 running api level 29, nor on my Samsung Galaxy Grand Prime running api level 22, so I
rewrote it using the PAW server documention as given here:
http://paw-android.fun2code.de/pdf/paw_functions.pdf
It has a built in function for getting the gps location as described on page 9.
To use this, follow the instructions as written above, except you'd start copying from line 33 onwards.
<bsh>
import de.fun2code.android.pawserver.AndroidInterface;
import org.json.*;
import android.location.*;
import java.text.SimpleDateFormat;
updated = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSZ");
activateGps(true);
loc = getGpsLocation();
i = 0;
while (i < 10 && loc == null)
{
Thread.sleep(100);
loc = getGpsLocation();
i++;
}
json = new JSONObject();
if (loc == null)
{
json.put("Success", false);
}
else
{
json.put("Success", true);
json.put("Updated", updated.format(loc.getTime()));
json.put("Latitude", loc.getLatitude());
json.put("Longitude", loc.getLongitude());
json.put("NumSatellites", loc.getExtras().getInt("satellites")); //could be 0 if using NETWORK_PROVIDER or phone isnt implementing it.
json.put("Altitude", loc.hasAltitude()?loc.getAltitude():0);
}
request.sendResponse(json.toString().getBytes(), "text/plain");
request.out.flush();
request.out.close();
</bsh>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment