Media Content Wi-Fi Hotspot with GPS Tracker

Media hotspot placed on bus can be accessed via Wi-Fi to view media content & also to track the devices using GPS co-ordinates sent to cloud

AdvancedFull instructions provided24 hours2,129
Media Content Wi-Fi Hotspot with GPS Tracker

Things used in this project

Hardware components

Raspberry Pi Zero Wireless
Raspberry Pi Zero Wireless
×1
Hologram Nova
Hologram Nova
×1
Hologram Global IoT SIM Card
Hologram Global IoT SIM Card
×1
OTG Cable
×1
U-blox Neo-6M GPS Module
×1
Mobile Power Bank
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian

Story

Read more

Schematics

GPS interface with Raspberry Pi

Use this schematic to interface GPS with Raspberry Pi, Note that the circuit shown here is with gps and raspberry pi 3 but the same pin connections will work even for raspberry pi zero w
Raspi with gps zukq9lmlfd

Circuit

Raspberry Pi Zero W with GPS receiver and hologram nova modem
Img 20180101 120033 duhf6qvikh i1o2seo4xa

Code

GPS.py

Python
Serial GPS data to Hologram.io cloud
import serial

#port = "/dev/ttyAMA0"  # Raspberry Pi 2
port = "/dev/ttyS0"    # Raspberry Pi 3 / Raspberry Pi Zero / Raspberry Pi Zero W

from Hologram.HologramCloud import HologramCloud
credentials = {'devicekey': 'mhdb84c0YTF3f39KzwNlm4iEfgo7h'}
cloud = HologramCloud(dict(), network='cellular')

def parseGPS(data):
#    print "raw:", data
    if data[0:6] == "$GPGGA":
        s = data.split(",")
        if s[7] == '0':
            print "no satellite data available"
            return        
        time = s[1][0:2] + ":" + s[1][2:4] + ":" + s[1][4:6]
        lat = decode(s[2])
        dirLat = s[3]
        lon = decode(s[4])
        dirLon = s[5]
        alt = s[9] + " m"
        sat = s[7]
        msg = "lat="+lat+"&log="+lon
        print msg
        cloud.sendMessage(msg, topics="GPSDATA", timeout=5)

def decode(coord):
    # DDDMM.MMMMM -> DD deg MM.MMMMM min
    v = coord.split(".")
    head = v[0]
    tail =  v[1]
    deg = head[0:-2]
    min = head[-2:]
    deg = float(deg)
    mintail = min+"."+ tail
    mintail = float(mintail)
    result = deg + mintail/60
    result = round(result,6)
    return str(result)

ser = serial.Serial(port, baudrate = 9600, timeout = 0.5)
while True:
    data = ser.readline()
    parseGPS(data)

app.js

JavaScript
NodeJS File
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');

mongoose.connect('mongodb://localhost:27017/Mapbro');
var Schema = mongoose.Schema;

var app = express();

var map = new Schema({
lat:String,
log:String,
time:Number
},{collection:'map-data'});   
var mapData = mongoose.model('mapData',map);
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.listen(3000);

app.get('/',function(req,res){
	res.render('index');
});

app.post('/setV',function(req,res){
console.log(req.body);  
var da = new Date();
        var json ={lat:req.param('lat'),
                log:req.param('log'),
                time:da.getTime()};
                mapData(json).save();
                res.send('Saved');
                res.end();

});

app.get('/send',function(req,res){
mapData.findOne({}).sort('-time')  // give me the max
  .exec(function (err, data) {

  	console.log(data);
  	res.send({x:data.lat,y:data.log});
  	  res.end();
  });

});

index.hbs

HTML
HTML File for NodeJS
<!DOCTYPE html>
<html>
  <head>
    <title>Simple Map</title>
    <meta name="viewport" content="initial-scale=1.0">
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <meta charset="utf-8">
    <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 100%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>
      var map;
      var marker;
function initMap() {
 map = new google.maps.Map(document.getElementById('map'), {
    zoom: 13,
    center: {lat: -25.363882, lng: 131.044922},
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });

  marker = new google.maps.Marker({
    position: map.getCenter(),
    icon: {
      path: google.maps.SymbolPath.CIRCLE,
      scale: 10
    },
    draggable: true,
    map: map
  });

}


function change_pos(result) {
	           var LatLong = new google.maps.LatLng(result.x,result.y);
    marker.setPosition(LatLong);
     var center = new google.maps.LatLng(result.x, result.y);
    // using global variable:
    map.panTo(center);


}

function test(){
	setInterval(function(){
	  $.getJSON("/send", function(result){            
	  	change_pos(result);
    });
	  },2000);
}


test();

    </script>
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAA-uM7eqNtLTEy226oVROaAZUMKFcDA5A&callback=initMap"
    async defer></script>
  </body>
</html>

Credits

Jayakarthigeyan Prabakar

Jayakarthigeyan Prabakar

2 projects • 6 followers
Rapid Prototyper | Product Developer | Systems Designer | IoT Specialist | Hardware Design Team Leader | Author | Web and App Developer
Hariharan Prabhakar

Hariharan Prabhakar

2 projects • 2 followers
Computer Engineer

Comments