Plotting UDP data live

1,370 views
Skip to first unread message

Ian Nesbitt

unread,
Sep 11, 2018, 11:01:16 PM9/11/18
to raspber...@googlegroups.com
Hello again everyone,

Richard's post today reminded me that I've been meaning to play around with the UDP data output feature in the new versions of the software for quite some time now. I thought I might be able to plot the UDP stream live as it's output from the shake. I'm sure it's easier some other way, but I'm most comfortable in Python, so I gave it a go.

If you'd like to take a look at my code, it's in Jupyter Notebook form, and I've saved it to GitHub. Hopefully you have as much fun watching it as me. It's utterly mesmerizing.

Enjoy.
Ian

out.gif



Ian Nesbitt

unread,
Sep 11, 2018, 11:07:03 PM9/11/18
to RaspberryShake
Looks like Google killed my gif, but it works on GitHub.

Ian Nesbitt

unread,
Sep 13, 2018, 8:45:17 PM9/13/18
to raspber...@googlegroups.com

I'm enjoying myself far too much with this when I should be working on my Master's research...

download.png


HS

unread,
Sep 14, 2018, 7:16:17 AM9/14/18
to RaspberryShake
Cool! Going to try it when I got finally got a shake up and running.

Ian Nesbitt

unread,
Sep 14, 2018, 10:35:56 AM9/14/18
to RaspberryShake
If you run into any problems, let me know. There's no obspy involved, so I think installing is relatively straightforward, but there could be snags I haven't thought to put in the README.

Ian

Branden Christensen

unread,
Sep 24, 2018, 5:35:13 PM9/24/18
to RaspberryShake
Ian:


I added a link to your code in the manual. Thank you for the contribution!



Yours, 


Branden Christensen
Director, Raspberry Shake project, Social Media: @raspishake

"Vive a tu manera" - Herencia de Timbiquí


On Fri, Sep 14, 2018 at 9:35 AM Ian Nesbitt <ian.n...@gmail.com> wrote:
If you run into any problems, let me know. There's no obspy involved, so I think installing is relatively straightforward, but there could be snags I haven't thought to put in the README.

Ian

--
Some useful links:
 
Manual: http://manual.raspberryshake.org/
Do It YourSelf Page: http://raspberryshake.org/do-it-yourself
Shop: https://shop.raspberryshake.org/
Website: http://raspberryshake.org/
 
Instagram: https://www.instagram.com/raspishake/
Facebook: https://www.facebook.com/raspishake/
Twitter: https://twitter.com/raspishake/
Hashtag: #rasperryshake, @raspishake
DOI: https://doi.org/10.7914/SN/AM
---
You received this message because you are subscribed to the Google Groups "RaspberryShake" group.
To unsubscribe from this group and stop receiving emails from it, send an email to raspberryshak...@googlegroups.com.
To post to this group, send email to raspber...@googlegroups.com.
Visit this group at https://groups.google.com/group/raspberryshake.
To view this discussion on the web visit https://groups.google.com/d/msgid/raspberryshake/7a4e4ee3-0844-4442-9570-56df855a3855%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ian Nesbitt

unread,
Sep 24, 2018, 8:23:32 PM9/24/18
to RaspberryShake
I'm honored!

Graham

unread,
Sep 26, 2018, 2:01:03 PM9/26/18
to RaspberryShake
Hi Ian
I have followed your instructions but cannot get it to work

in my UDP-data-strams.conf I have

 "UDP-destinations" : [
        { "dest" : "UDP-SHAKE-PI"},
        { "dest" : "UDP-NETWORK-PI"}
    ],

    "UDP-SHAKE-PI" : {
        "Hostname" : "UDPIPFILE:/opt/settings/sys/ip.txt",
        "Port" :         "54321"
    },

    "UDP-NETWORK-PI" : {
        "Hostname" : "192.168.0.77",
        "Port" :         "18002"

Then in the browser window I have host as ' ' and port set to 18002

But when I click on Cell-> Run all I get the following which doesnt mean a lot to me

OSError                                   Traceback (most recent call last)
<ipython-input-28-31e41a729ebd> in <module>()
     16 per_lap = 0.9
     17 mult = 8.0
---> 18 sock = s.socket(s.AF_INET, s.SOCK_DGRAM | s.SO_REUSEADDR)
     19 sock.bind((host, port))
     20 

T:\Anaconda\lib\socket.py in __init__(self, family, type, proto, fileno)
    142         # constructor of _socket.socket converts the given argument to an
    143         # integer automatically.
--> 144         _socket.socket.__init__(self, family, type, proto, fileno)
    145         self._io_refs = 0
    146         self._closed = False

OSError: [WinError 10044] The support for the specified socket type does not exist in this address family


Any Ideas

Kind Regards

Graham

Ian Nesbitt

unread,
Sep 26, 2018, 8:40:35 PM9/26/18
to raspber...@googlegroups.com
Graham,

Are you running Jupyter on Windows? Windows may require you to put an address in the host = '' quotations. I don't specifically know what will work since I'm unable to test on Windows at the moment, but it should be either of the following:

host = '127.0.0.1'
or
host = 'localhost'

These essentially mean the same thing, but Windows may require you to define them explicitly.

The only other thing that comes to mind would be a permissions issue, but we'll cross that road if this doesn't work for you.

Ian

Graham

unread,
Sep 27, 2018, 3:01:37 AM9/27/18
to RaspberryShake
Hi Ian

Yes I'm running on Windows 10

I have tried that with no success so it may be a permissions thing . I have also set up a rule in the firewall to open that port and also turned the firewall off but no difference

Regards

Graham

Richard

unread,
Sep 27, 2018, 8:06:59 AM9/27/18
to raspber...@googlegroups.com
hi graham,

the error message is coming from the Operating System and is telling you that UDP protocol is not supported by the underlying Socket package that is installed on the computer.  (SOCK_DGRAM is a Socket Datagram, which is a UDP data packet.)

try to implement a simple example and see what happens:

code to receive UDP data:

==== BEGIN CODE SNIPPET ====
import socket

UDP_IP = "127.0.0.1"
UDP_PORT = 5005

sock = socket.socket(socket.AF_INET, # Internet
                     socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))

while True:
    data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
    print "received message:", data
==== END CODE SNIPPET ====

and the code to send a UDP message:

==== BEGIN CODE SNIPPET ====
import socket

UDP_IP = "127.0.0.1"
UDP_PORT = 5005
MESSAGE = "Hello, World!"

print "UDP target IP:", UDP_IP
print "UDP target port:", UDP_PORT
print "message:", MESSAGE

sock = socket.socket(socket.AF_INET, # Internet
                     socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
==== END CODE SNIPPET ====

does that work?  or do you get the same error?  i'm not sure how you installed python, but you might want to confirm your installation in some other way.

cheers,

richard

Graham

unread,
Sep 27, 2018, 8:20:20 AM9/27/18
to RaspberryShake
Hi Richard

OK I'll give that a try but how to I run the code

Do I run it in a batch file on on a browser window when i open jupyter-notebook

As you may gather this is new to me

I have Anaconda installed

Kind Regards

Graham

Ian Nesbitt

unread,
Oct 26, 2018, 2:12:50 PM10/26/18
to RaspberryShake
TideMan has informed me that he is able to get my UDP live plotting software to run smoothly on a Raspberry Pi 3. I've updated the README to include a link describing how to install Jupyter Notebook on a RPi3 so you can too!


Ian

Ian Nesbitt

unread,
Feb 17, 2019, 12:26:59 AM2/17/19
to RaspberryShake
Graham,

I just found your post again and apologize for not responding properly several months ago. I promise I wasn't trying to ignore you!

Are you by chance running firewall or antivirus software on your Windows machine? That could definitely prevent python from opening a socket.

Ian
Reply all
Reply to author
Forward
0 new messages