Hey Guys,
I am trying to develop a Earthquake prediction model through seismic waves. Kindly let mw know how can I access realtime data in my Laptop?
On the web interface, go to: Settings → Datacast
Enter the IP of your laptop and port of your choice. I use 8888 because I know that at least on my network, nothing else uses UDP port 8888.
Then on your laptop you will receive a stream of UDP packets on port 8888 containing the raw data:
{'EHZ', 1706723359.445, 16634, 16729, 16719, 16744, 16756, 16684, 16747, 16700, 16753, 16715, 16741, 16664, 16608, 16688, 16536, 16646, 16636, 16653, 16800, 16675, 16609, 16551, 16612, 16681, 16608}
{'HDF', 1706723359.445, 12794, 12712, 11815, 12524, 13927, 13170, 11940, 11761, 11800, 12157, 12470, 12685, 13719, 13293, 13273, 12588, 13240, 15722, 14298, 12562, 12004, 12476, 12066, 11650, 12949}
This is from my shake/boom, so I get data from the seismometer (EHZ) and from the infrasound detector (HDF).
The first component in the list is the time, then a series of “counts” values.
Just to add our dedicated manual page to Philip’s answer above, which already describes what you are required to do regarding UDP data transmission.
You can find all the details here: Raspberry Shake Data Producer UDP Port Output
Hey,
Where in code i have to add it?
Secondly I only want to access it in my laptop. Is it possible?
You specify the IP address of your laptop – to the data only goes to your laptop.
How you code it depends on what programming language you are using. You probably need to find someone local to you to help with that.
Here is a sample piece of C code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <limits.h>
#include <errno.h>
#include <time.h>
#include <sys/stat.h>
#define PORT 8888
#define CHANNEL "EHZ"
#define BUFSIZE 1024
#define TRIGGER 1000
#define WINDOW 10
#define ALERT "./detect-alert"
int main(int argc, char **argv) {
char *ep, chan[4] = CHANNEL;
int sockfd, ch, vflag = 0, lflag=0, win = WINDOW;
long trigger = TRIGGER;
char buffer[BUFSIZE];
struct sockaddr_in servaddr;
struct stat f_stats;
// Process arguments (if any)
while ((ch = getopt(argc, argv, "lvt:w:c:")) != -1) {
switch (ch) {
case 'l':
lflag = 1;
break;
case 'v':
vflag = 1;
break;
case 'c':
strncpy(chan, optarg, 3);
break;
case 't':
if (!(trigger = strtol(optarg, &ep, 0))) {
fprintf(stderr, "Incorrect trigger value: %s integer required\n", optarg);
exit(1);
}
break;
case 'w':
if (!(win = (int) strtol(optarg, &ep, 0))) {
fprintf(stderr, "Incorrect window value: %s integer required\n", optarg);
exit(1);
}
break;
default:
printf("Usage: %s [-l] [-v] [-t trigger] [-w window] [-c channel]\n", argv[0]);
exit(1);
}
}
// Create socket to listen for UDP data from r-shake
if ( (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0 ) {
perror("socket creation failed");
exit(EXIT_FAILURE);
}
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PORT);
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
bind(sockfd, (struct sockaddr *)&servaddr, sizeof(struct sockaddr));
int n, c = 1000;
char *str, *endptr, buf[100];
long val, a_val, av = 16500L, f_av = 0L;
socklen_t len;
// Read a UDP packet
while ((n = recvfrom(sockfd, (char *)buffer, BUFSIZE, 0, (struct sockaddr *) &servaddr, (socklen_t *) &len)) > 0) {
buffer[n] = '\0';
// Skip if not wanted channel data
if (strncmp(buffer+2, chan, 3)) continue;
if (lflag) printf("%s\n", buffer);
endptr = str = buffer + 24; // Skip sensor name and timestamp
// Process the packet data -- note built-in assumptions about format
while (*endptr != '}') {
errno = 0;
val = strtol(str, &endptr, 0);
str = endptr + 1;
// Calculate a rolling average over 250 data points
av = av + ((val - av)/(250 +1));
// Abs deviation from average
a_val = labs(av - val);
// Rolling average over 10 values - by default
f_av = f_av + ((a_val - f_av)/(win +1));
// Countdown to allow average to stabilize, or dead period after detecting event
if (c) {
if (((c%100) == 0) && vflag)
{
char msg[100];
sprintf(msg, "%10i\r", c); write(1, msg, strlen(msg));
}
--c;
continue;
}
if (vflag) {
sprintf(buf, "%10ld\r", f_av); write(1, buf, strlen(buf));
}
// Check abs value of latest data point to see if it exceeds the trigger point
if (labs(f_av) > trigger) {
struct tm *utc_time;
time_t t;
char *p;
// Print a message with timestamp (local TZ)
t = (time_t) strtol(buffer+7, &p, 0);
utc_time = gmtime(&t);
p = asctime(utc_time);
*(strchr(p, '\n')) = '\0'; // Who ever thought it a good idea to add a newline!
printf("Event detected: %s (UTC)\n", p);
// Pause for 30 seconds
c = 3000;
if ((stat(ALERT, &f_stats) == 0) && (f_stats.st_mode & X_OK)) system(ALERT);
}
}
}
close(sockfd);
return 0;
}
And a bit of documentation on what it is doing: