Jaume Miralles
Published © GPL3+

Basic Warwalking with a Raspberry

An straight an reliable way to gather field data, posting it in real time to the web and having the CSV or KML available to download.

IntermediateProtip3 hours1,453
Basic Warwalking with a Raspberry

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
USB GPS receiver
×1
USB external battery
×1

Software apps and online services

circusofthings.com

Story

Read more

Schematics

Scheme

Basic scheme of blocks involved

Code

CircusField.java

Java
A working example to do a warwalking. It will count the number of SSIDs in each GPS coordinates and report this number to Circus Of Things.
package circusfield;
  
import com.circusofthings.api.ver110.CircusLib;
import com.jaumemirallesisern.hardware.GPSNMEAserial;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
  
public class CircusField {
  
   private static final String KEY = "your_key_signal_at_circus_here";
   private static final String TOKEN = "your_circus_token_here";
   private static final int FREC = 10000; // as set in signal's parameters
   private static GPSNMEAserial gpsnmea;
  
   private static void mountGPS() {
       try {
           gpsnmea = new GPSNMEAserial(4800,"/dev/ttyUSB0");
       } catch (Exception e) {
           System.out.println("Error reaching gpsnmeaserial");
       }
   }
  
   private static int runLinuxCommand(){
       String s;
       Process p;
       int counter = 0;
       try {
           p = Runtime.getRuntime().exec("sudo iw dev wlan0 scan ");
           BufferedReader br = new BufferedReader(
               new InputStreamReader(p.getInputStream()));
           while ((s = br.readLine()) != null) {
               if(s.contains("SSID")){
               System.out.println("line: " + s);
               counter++;}
           }
           p.waitFor();
           System.out.println ("exit: " + p.exitValue());
           p.destroy();
           return counter;
       } catch (IOException | InterruptedException e) {return counter;}
   }
   protected static void delay(int t) {
       try {   
           Thread.sleep(t);
       } catch(InterruptedException e) {
       }
   }
   public static void main(String[] args) {
       mountGPS();
       CircusLib commands = new CircusLib(TOKEN);
       double lat;
       double lon;
       double alt;
       int nsats;
       double value;
       for (;;) {
           try {
               gpsnmea.receiveUARTData();
           } catch(Exception e){System.out.println("Error reading serial");}
           delay(100);
           value = runLinuxCommand();
           lat = gpsnmea.getLat();
           lon = gpsnmea.getLon();
           alt = gpsnmea.getAlt();
           nsats = gpsnmea.getNsats();
           if (!(lat==0&&lon==0)) {
               System.out.println("Write to Circus: "+KEY);
               System.out.println(lat+" - "+lon+" - "+alt+" - "+nsats);
               JSONObject obj = commands.writeValue(KEY, value, lat, lon, alt);
               System.out.println("Circus response: "+obj.toString());
           }
           delay(FREC);
       }
   }
}

Credits

Jaume Miralles

Jaume Miralles

5 projects • 34 followers

Comments