Skip to content

Instantly share code, notes, and snippets.

@Gambiit
Created March 21, 2014 10:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Gambiit/f9520d048cb7ccb9e40a to your computer and use it in GitHub Desktop.
Save Gambiit/f9520d048cb7ccb9e40a to your computer and use it in GitHub Desktop.
flow gps raw from your raspberry to websocket

Gps device is the adafruit Ultimate gps build around the MTK3339 chipset.

Plug your device on the UART of the rpi or with a usb adaptator (you have to change serial port config /dev/ttyAMA0 to /dev/ttyUSB0).

Look the raw at the debug node. Send command to gps like STANDBY. Look at http://learn.adafruit.com. to complete documentation.

Mkdir /home/pi/mygps on your raspberry and paste this html example

<!DOCTYPE HTML>
<html>
    <head>
        <title>AdafruitUltimateGps</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        
        
    </head>
    <script type="text/javascript">
        var server = window.location.hostname;
        var topics = {};
        var wsUriC = "ws://"+server+":1880/admin/ws/example";
        function wsConnectC() {
            console.log("connect",wsUriC);
            var ws = new WebSocket(wsUriC);
            ws.onmessage = function(msg) {
                var line = "";
                var msggps = JSON.parse(msg.data);
                //console.log(msggps);
                for (var cle in msggps) {
                line += "<tr><td>" + cle + "</td><td>" + msggps[cle] + "</td></tr>";
                }
                document.getElementById('gps').innerHTML = line;
                // document.getElementById('lon').innerHTML = msg.data.lon;
            }
            ws.onopen = function() {
                document.getElementById('status').innerHTML = "connected";
                console.log("connected");
            }
            ws.onclose = function() {
                document.getElementById('status').innerHTML = "not connected";
                setTimeout(wsConnectC,1000);
            }
        }
    </script>
    <body onload="wsConnectC();" onunload="ws.disconnect;">
        <div data-role = "page" id="one">
          <h1>GPS from rapsberry</h1>
        
          <table id="gps">
            <tr>
              <th>Attribut</th>
              <th>Valeur</th>
            </tr>
        
        </div>
        
        <div id="status">unknown</div>
    </body>

Uncomment this sentences on your ~/node-red/setting.js file

...
    //When httpAdminRoot is used to move the UI to a different root path, the
    // following property can be used to identify a directory of static content
    // that should be served at http://localhost:1880/.
    httpStatic: '/home/pi/mygps/',

    // To password protect the static content, the following property can be used.
    // The password must be an md5 hash  eg.. 5f4dcc3b5aa765d61d8327deb882cf99 ('password')
    //httpStaticAuth: {user:"user",pass:"5f4dcc3b5aa765d61d8327deb882cf99"},
    
    // The following property can be used in place of 'httpAdminRoot' and 'httpNodeRoot',
    // to apply the same root to both parts.
    httpRoot: '/admin',
...

Then access at http://yourraspberryIP:1880 or http://yourraspberryIP:1880/admin

[{"id":"f228d9e7.a3c27","type":"websocket-listener","path":"/ws/example","wholemsg":"false"},{"id":"789db273.d1624c","type":"serial-port","serialport":"/dev/ttyAMA0","serialbaud":"9600","newline":"\\r\\n","addchar":"true"},{"id":"bffc2e19.1b476","type":"serial in","name":"rx AdaFruitGPS","serial":"789db273.d1624c","x":388,"y":185,"z":"abcde1ad.8d165","wires":[["aa3e78f4.625e5"]]},{"id":"5f292df1.8896ac","type":"inject","name":"STANDBY","topic":"","payload":"$PMTK161,0*28","payloadType":"string","repeat":"","crontab":"","once":false,"x":198,"y":328,"z":"abcde1ad.8d165","wires":[["e7e39a20.8d91f8"]]},{"id":"e7e39a20.8d91f8","type":"serial out","name":"tx AdaFruitGPS","serial":"789db273.d1624c","x":389,"y":105,"z":"abcde1ad.8d165","wires":[]},{"id":"a60da060.be0a5","type":"inject","name":"AWAKE","topic":"","payload":"$PMTK010,002*2D","payloadType":"string","repeat":"","crontab":"","once":false,"x":201,"y":410,"z":"abcde1ad.8d165","wires":[["e7e39a20.8d91f8"]]},{"id":"d730fb.e87be708","type":"inject","name":"FIRMWARE","topic":"","payload":"$PMTK605*31","payloadType":"string","repeat":"","crontab":"","once":false,"x":202,"y":484,"z":"abcde1ad.8d165","wires":[["e7e39a20.8d91f8"]]},{"id":"aa3e78f4.625e5","type":"switch","name":"Route raw","property":"payload","rules":[{"t":"cont","v":"$PMTK"},{"t":"cont","v":"$GPRMC"}],"checkall":"false","outputs":2,"x":483,"y":268,"z":"abcde1ad.8d165","wires":[[],["6030f447.4d0c8c"]]},{"id":"be87799b.03408","type":"inject","name":"RMC Only","topic":"","payload":"$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29","payloadType":"string","repeat":"","crontab":"","once":false,"x":196,"y":567,"z":"abcde1ad.8d165","wires":[["e7e39a20.8d91f8"]]},{"id":"ff92c64b.059c38","type":"websocket out","name":"gpsws","server":"f228d9e7.a3c27","x":687,"y":425,"z":"abcde1ad.8d165","wires":[]},{"id":"4bff9d60.deadb4","type":"debug","name":"","active":false,"complete":"true","x":681,"y":264,"z":"abcde1ad.8d165","wires":[]},{"id":"6030f447.4d0c8c","type":"function","name":"RMC","func":"// The received message is stored in 'msg'\n// It will have at least a 'payload' property:\n// console.log(msg.payload);\n// The 'context' object is available to store state\n// between invocations of the function\n// context = {};\n\nvar RMC = msg.payload.split(',');\n\nmsg.payload = {\n\t\"CLASS\":RMC[0],\n\t\"UTC\":RMC[1],\n\t\"STATUS\":RMC[2],\n\t\"LAT\":RMC[3]/100+RMC[4],\n\t//\"N-S\":RMC[4],\n\t\"LON\":RMC[5]/100+RMC[6],\n\t//\"E-O\":RMC[6],\n\t\"VTG\":RMC[7],\n\t\"cap\":RMC[8],\n\t\"DATE\":RMC[9]\n};\nreturn msg;","outputs":1,"x":593,"y":345,"z":"abcde1ad.8d165","wires":[["ff92c64b.059c38","4bff9d60.deadb4"]]},{"id":"74b37984.715d5","type":"comment","name":"Commande MTK2339","info":"Les différentes commandes du global star MTK3339","x":155,"y":257,"z":"abcde1ad.8d165","wires":[]},{"id":"b35743d5.f7f258","type":"comment","name":"port serie /dev/ttyAMA0","info":"","x":396,"y":146,"z":"abcde1ad.8d165","wires":[]},{"id":"724bfaa2.7acf8c","type":"comment","name":"Websocket","info":"","x":690,"y":469,"z":"abcde1ad.8d165","wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment