RESTful interface for ECG / EEG sensor data in haskell

I am working on a project in which I want to display EEG / ECG biosensor data measured by a portable device (for example, a microcontroller with wireless data transmission via Wi-Fi or Bluetooth). For this I need to communicate with a portable device / microcontroller for which many or some devices use RESTful interfaces , but the suggestion is also possible sockets.

One example of a Wi-Fi microcontroller is "spark.io" which is based on the mortor m3 and CC3000 controller for onboard WiFi access. The data to be transferred ranges from 500 to 1000 floating point values ​​per second, which should arrive at the REST client with minimal latency. Probably a non-REST approach like sockets would work better, but I'd still like to test the RESTFul-based approach (the tiny argument for this is that passing data through the RESFul interface seems very common and has good library support).

Q: The question is, what is the best approach to implement an executor (in a near real-time sense) that communicates with it via a REST interface?

I'm sure this issue has been resolved before, but I haven't been able to quickly find an article via a Google researcher or tech / science blog that explains this. The only link I've found is for "rest hooks" , but I'm not sure if this is a good approach. A SE search did not reveal a past question about this.

Side note. My approach is to first implement the interface in haskell to test the design and performance of the RESFull interface. Later, the working approach should be ported or implemented with Java / Android / spark.io / another microcontroller.

(Please note that this question is about architecture and not about haskell libraries or anything like that. If using REST is the hardest thing to do, I'll agree with it as an answer if it's argued. microcontroller web interfaces and in particular their APIs like "spark.io" are generally a silly idea if implemented via REST. If so? If not, what's the definition of "near real time" justifies that a REST interface is a bad idea, and therefore other communication tools are better. For example, is one sensor read per minute? Or once a second, for 1/10 of a second, for 1/100 of a second, for 1/1000 seconds? )

+3


source to share


1 answer


Ok, skip this.

REST isn't necessarily a bad idea, but it has a lot of features that you might not need. For example, there are REST verbs not only for searching, but also for updating, deleting, and creating resources. If these functions are important (for example, you need to send certain control data to the EEG controller) then REST will be nice. If you need fast access to a stream of data, consider raw TCP instead.

Likewise, REST will send messages to "requests" and their "responses" which contain a bunch of "headers" indicating things like executing the request, compressing it, etc. These can be great features, but they can get bloated. You probably want to release enough data for each request so that ~ 1kB of headers are a small part of it. But given the 8 byte float ( double

s) that require 500-1000 data points to transfer, which you said would take about one second. Is it our destiny to always have 1 with a delay?

REST allows you to avoid some of this bloat by declaring Transfer-Encoding: chunked

so that the client can work on individual chunks as they become available. So the architectural decision that I think will need to be made.



I would definitely work Keep-Alive

as soon as possible and that would be my main function when looking for a library to be used on the server. Keep-Alive

is a standard HTTP extension that avoids breaking and rebuilding the TCP stack for every HTTP request. If you don't, you will have a heavy negotiation protocol every time you submit a request.

The critical decision you will need to make includes whether you want HTTP pipelining or not. You can combine HTTP pipelining with longer requests (those in which you don't expect an immediate response), essentially "send data when it becomes available" (i.e. send headers first and let the server push data when it's available) good and done). This is an alternative to channel transmission.

If you can work with them, the HTTP server is regularly used to send megabytes per second, so your use case is fine for what REST can do. From the point of view of libraries REST / HTTP for the Haskell, if you need to somehow program the controller alone, more parameters: wai

, yesod

, snap

and rest

. If you just need an HTTP client, there are some of them.

+3


source







All Articles