{"id":1545,"date":"2014-06-06T17:50:23","date_gmt":"2014-06-06T15:50:23","guid":{"rendered":"http:\/\/blog.herrwolff.org\/?p=1545"},"modified":"2014-06-09T16:49:16","modified_gmt":"2014-06-09T14:49:16","slug":"arduino-datenvisualisierung-mit-nodejs","status":"publish","type":"post","link":"http:\/\/blog.herrwolff.org\/?p=1545","title":{"rendered":"Arduino &#8212; Datenvisualisierung mit NodeJS"},"content":{"rendered":"<h1> Zusammenfassung <\/h1>\n<p>In diesem Beitrag soll erkl\u00e4rt werden, wie mit einem Arduino Uno Daten erfasst werden und mittels JSON an einen WebServer \u00fcbermittelt werden k\u00f6nnen. Mit Hilfe von NodeJS wird ein WebSever aufgebaut, der die vom Arduino \u00fcbermittelten Daten verarbeitet und in einem Diagramm dargestellt. Ich verwende dazu das GitHub Projekt <a href=\"https:\/\/github.com\/billroy\/arduino-livechart\" title=\"arduino-livechart\" target=\"_blank\">arduino-livechart<\/a>, bei dem (da in der neuen Version von express.js keine Middleware mehr enthalten ist) einige Anpassungen n\u00f6tig sind, damit die aktuelle Version von NodeJS verwendet werden kann.<br \/>\n<div data-carousel-extra='{\"blog_id\":1,\"permalink\":\"http:\\\/\\\/blog.herrwolff.org\\\/?p=1545\"}' id='gallery-1' class='gallery galleryid-1545 gallery-columns-2 gallery-size-thumbnail'><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2014\/06\/sample-chart.png'><img width=\"150\" height=\"75\" src=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2014\/06\/sample-chart-150x75.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"\" loading=\"lazy\" data-attachment-id=\"1761\" data-permalink=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2014\/06\/sample-chart.png\" data-orig-file=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2014\/06\/sample-chart.png\" data-orig-size=\"1045,613\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"sample-chart\" data-image-description=\"\" data-medium-file=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2014\/06\/sample-chart-300x175.png\" data-large-file=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2014\/06\/sample-chart-1024x600.png\" \/><\/a>\n\t\t\t<\/div><\/figure><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2014\/06\/WebApp.png'><img width=\"150\" height=\"75\" src=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2014\/06\/WebApp-150x75.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"\" loading=\"lazy\" data-attachment-id=\"1766\" data-permalink=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2014\/06\/WebApp.png\" data-orig-file=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2014\/06\/WebApp.png\" data-orig-size=\"606,264\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"WebApp\" data-image-description=\"\" data-medium-file=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2014\/06\/WebApp-300x130.png\" data-large-file=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2014\/06\/WebApp.png\" \/><\/a>\n\t\t\t<\/div><\/figure>\n\t\t<\/div>\n<br \/>\n<!--more--><\/p>\n<h2> Eine Node-WebApp um die gesendeten Daten auf einer WebSeite darzustellen <\/h2>\n<p>Die WebApp besteht aus drei Teil:<\/p>\n<ul>\n<li>Dem Arduino Uno Sketch sendet JSON-Daten<\/li>\n<li>Dem Backend: Ein ExpressJS-WebServer mit Datensteicherung<\/li>\n<li>Dem Frontend: Darstellung der Daten mit Hilfe der JS-Bibliothek d3js<\/li>\n<\/ul>\n<p>Download: <a href=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2014\/06\/WebServer.zip\" title=\"WebServer.zip\" target=\"_blank\">WebServer.zip<\/a><br \/>\n<img src=\"\/\/s0.wp.com\/latex.php?latex=%3Cbr+%2F%3E+%5Cbegin%7Btikzpicture%7D%5Bscale%3D2%5D%3C%2Fp%3E+%3Cp%3E%25+Include+tikz+into+local+preamble%3Cbr+%2F%3E+%5B%2Bpreamble%5D%3Cbr+%2F%3E++++++%5Cusepackage%7Btikz%7D%3Cbr+%2F%3E++++++%5Cusepackage%7Bcolor%7D%3Cbr+%2F%3E++++++%5Cusepackage%7Bxcolor%7D%3Cbr+%2F%3E++++++%5Ctikzstyle%7Bsensor%7D%3D%5Bdraw%2C+fill%3Dblue%2120%2C+text+width%3D8em%2C%3Cbr+%2F%3E+++++text+centered%2C+minimum+height%3D2.5em%5D%3Cbr+%2F%3E++++++%5Ctikzstyle%7Bwebserver%7D+%3D+%5Bsensor%2C+text+width%3D8em%2C+fill%3Dred%2120%2C%3Cbr+%2F%3E+++++minimum+height%3D8em%2C+rounded+corners%5D%3Cbr+%2F%3E++++++%5Ctikzstyle%7Bindex%7D+%3D+%5Bsensor%2C+text+width%3D8em%2C+fill%3Dgreen%2120%2C%3Cbr+%2F%3E+++++minimum+height%3D8em%2C+rounded+corners%5D%3Cbr+%2F%3E++++++%5Ctikzstyle%7Barduino%7D+%3D+%5Bsensor%2C+fill%3Dblue%2120%2C%3Cbr+%2F%3E+++++minimum+height%3D8em%2C+rounded+corners%5D%3Cbr+%2F%3E++++++%5Ctikzstyle%7Bd3js%7D+%3D+%5Bsensor%2C+text+width%3D8em%2C+fill%3Dorange%2120%2C%3Cbr+%2F%3E+++++minimum+height%3D3em%2C+rounded+corners%5D%3Cbr+%2F%3E++++++%5Ctikzstyle%7Bexpress%7D+%3D+%5Bsensor%2C+minimum+width%3D3em%2C+fill%3Dorange%2120%2C%3Cbr+%2F%3E+++++minimum+height%3D3em%2C+rounded+corners%5D%3Cbr+%2F%3E++++++%5Cdef%5Cblockdist%7B2.%7D%3Cbr+%2F%3E+%5B%2Fpreamble%5D%3Cbr+%2F%3E+++%5Cnode%28webserver%29+%5Bwebserver%5D+%7B%5Cbegin%7Btabular%7D%7Bc%7D+%5Ctextbf%7BWebServer.js%7D%5C%5C%5Cscriptsize+nodeJS+based+%5C%5C%5Cscriptsize+++%5Cend%7Btabular%7D%7D+%3B%3Cbr+%2F%3E+++%5Cpath+%28socket.west%29%2B%28-%5Cblockdist%2C0%29+node+%28index%29+%5Bindex%5D+%7B%5Ctextbf%7Bindex.html%7D%7D%3B%3Cbr+%2F%3E+++%5Cpath+%28index.south%29+%2B+%280%2C-0.3%29+node+%28d3js%29+%5Bd3js%5D+%7B%5Ctextbf%7Bd3js%7D%7D%3B%3Cbr+%2F%3E+++%5Cpath+%28index.north%29%2B%280%2C0.5%29+node+%28fe%29+%7B%5Cbegin%7Btabular%7D%7Bc%7D+%5Ctextbf%7Bfrontend%7D++%5C%5C%5Cscriptsize+happens+in+the+browser+%5Cend%7Btabular%7D%7D%3B%3Cbr+%2F%3E+++%5Cpath+%28webserver.east%29%2B%28%5Cblockdist%2C-0%29+node+%28arduino%29+%5Barduino%5D+%7B%5Cbegin%7Btabular%7D%7Bc%7D+%5Ctextbf%7BWebClient.ino%7D%5C%5C%5Cscriptsize+JSON++%5C%5C%5Cscriptsize+Arduino+Sketch+%5Cend%7Btabular%7D%7D%3B%3Cbr+%2F%3E+++%5Cpath+%28arduino.north%29%2B%280%2C0.5%29+node+%28fe%29+%7B%5Cbegin%7Btabular%7D%7Bc%7D+%5Ctextbf%7Bsensor%7D++%5C%5C%5Cscriptsize+happens+in+the+arduino+uno+%5Cend%7Btabular%7D%7D%3B%3Cbr+%2F%3E+++%5Cpath+%28webserver.south%29+%2B+%280%2C-0.3%29+node+%28express%29+%5Bexpress%5D+%7B%5Cbegin%7Btabular%7D%7Bc%7D+%5Ctextbf%7Bexpress.js%7D%5C%5C%5Cscriptsize+WebServer+%5Cend%7Btabular%7D%7D%3B%3Cbr+%2F%3E+++%5Cpath+%28webserver.north%29%2B%280%2C0.5%29+node+%28be%29+%7B%5Cbegin%7Btabular%7D%7Bc%7D%5Ctextbf%7Bbackend%7D+%5C%5C%5Cscriptsize+happens+on+the+server%5Cend%7Btabular%7D%7D%3B%3Cbr+%2F%3E+++%5Cdraw+%5Bblack%2C+fill%3Dgray%2150%2C+fill+opacity%3D0.3%2C+dashed%2C+rounded+corners%5D%28%24%28index.north+west%29%2B%28-10pt%2C30pt%29%24%29++--+%28%24%28index.north+east%29%2B%2830pt%2C30pt%29%24%29+--+%28%24%28index.south+east%29%2B%2830pt%2C-50pt%29%24%29+--+%28%24%28index.south+west%29%2B+%28-10pt%2C-50pt%29%24%29+--+cycle%3B%3Cbr+%2F%3E+++%5Cdraw+%5Bblack%2C+fill%3Dgray%2150%2C+fill+opacity%3D0.3%2C+dashed%2C+rounded+corners%5D%28%24%28arduino.north+west%29%2B%28-30pt%2C30pt%29%24%29++--+%28%24%28arduino.north+east%29%2B%2810pt%2C30pt%29%24%29+--+%28%24%28arduino.south+east%29%2B%2810pt%2C-50pt%29%24%29+--+%28%24%28arduino.south+west%29%2B+%28-30pt%2C-50pt%29%24%29+--+cycle%3B%3C%2Fp%3E+%3Cp%3E%5Cend%7Btikzpicture%7D%3Cbr+%2F%3E+&#038;bg=ffffff&#038;fg=000&#038;s=0\" alt=\"&lt;br \/&gt; &#92;begin{tikzpicture}[scale=2]&lt;\/p&gt; &lt;p&gt;% Include tikz into local preamble&lt;br \/&gt; [+preamble]&lt;br \/&gt;      &#92;usepackage{tikz}&lt;br \/&gt;      &#92;usepackage{color}&lt;br \/&gt;      &#92;usepackage{xcolor}&lt;br \/&gt;      &#92;tikzstyle{sensor}=[draw, fill=blue!20, text width=8em,&lt;br \/&gt;     text centered, minimum height=2.5em]&lt;br \/&gt;      &#92;tikzstyle{webserver} = [sensor, text width=8em, fill=red!20,&lt;br \/&gt;     minimum height=8em, rounded corners]&lt;br \/&gt;      &#92;tikzstyle{index} = [sensor, text width=8em, fill=green!20,&lt;br \/&gt;     minimum height=8em, rounded corners]&lt;br \/&gt;      &#92;tikzstyle{arduino} = [sensor, fill=blue!20,&lt;br \/&gt;     minimum height=8em, rounded corners]&lt;br \/&gt;      &#92;tikzstyle{d3js} = [sensor, text width=8em, fill=orange!20,&lt;br \/&gt;     minimum height=3em, rounded corners]&lt;br \/&gt;      &#92;tikzstyle{express} = [sensor, minimum width=3em, fill=orange!20,&lt;br \/&gt;     minimum height=3em, rounded corners]&lt;br \/&gt;      &#92;def&#92;blockdist{2.}&lt;br \/&gt; [\/preamble]&lt;br \/&gt;   &#92;node(webserver) [webserver] {&#92;begin{tabular}{c} &#92;textbf{WebServer.js}&#92;&#92;&#92;scriptsize nodeJS based &#92;&#92;&#92;scriptsize   &#92;end{tabular}} ;&lt;br \/&gt;   &#92;path (socket.west)+(-&#92;blockdist,0) node (index) [index] {&#92;textbf{index.html}};&lt;br \/&gt;   &#92;path (index.south) + (0,-0.3) node (d3js) [d3js] {&#92;textbf{d3js}};&lt;br \/&gt;   &#92;path (index.north)+(0,0.5) node (fe) {&#92;begin{tabular}{c} &#92;textbf{frontend}  &#92;&#92;&#92;scriptsize happens in the browser &#92;end{tabular}};&lt;br \/&gt;   &#92;path (webserver.east)+(&#92;blockdist,-0) node (arduino) [arduino] {&#92;begin{tabular}{c} &#92;textbf{WebClient.ino}&#92;&#92;&#92;scriptsize JSON  &#92;&#92;&#92;scriptsize Arduino Sketch &#92;end{tabular}};&lt;br \/&gt;   &#92;path (arduino.north)+(0,0.5) node (fe) {&#92;begin{tabular}{c} &#92;textbf{sensor}  &#92;&#92;&#92;scriptsize happens in the arduino uno &#92;end{tabular}};&lt;br \/&gt;   &#92;path (webserver.south) + (0,-0.3) node (express) [express] {&#92;begin{tabular}{c} &#92;textbf{express.js}&#92;&#92;&#92;scriptsize WebServer &#92;end{tabular}};&lt;br \/&gt;   &#92;path (webserver.north)+(0,0.5) node (be) {&#92;begin{tabular}{c}&#92;textbf{backend} &#92;&#92;&#92;scriptsize happens on the server&#92;end{tabular}};&lt;br \/&gt;   &#92;draw [black, fill=gray!50, fill opacity=0.3, dashed, rounded corners]($(index.north west)+(-10pt,30pt)$)  -- ($(index.north east)+(30pt,30pt)$) -- ($(index.south east)+(30pt,-50pt)$) -- ($(index.south west)+ (-10pt,-50pt)$) -- cycle;&lt;br \/&gt;   &#92;draw [black, fill=gray!50, fill opacity=0.3, dashed, rounded corners]($(arduino.north west)+(-30pt,30pt)$)  -- ($(arduino.north east)+(10pt,30pt)$) -- ($(arduino.south east)+(10pt,-50pt)$) -- ($(arduino.south west)+ (-30pt,-50pt)$) -- cycle;&lt;\/p&gt; &lt;p&gt;&#92;end{tikzpicture}&lt;br \/&gt; \" title=\"&lt;br \/&gt; &#92;begin{tikzpicture}[scale=2]&lt;\/p&gt; &lt;p&gt;% Include tikz into local preamble&lt;br \/&gt; [+preamble]&lt;br \/&gt;      &#92;usepackage{tikz}&lt;br \/&gt;      &#92;usepackage{color}&lt;br \/&gt;      &#92;usepackage{xcolor}&lt;br \/&gt;      &#92;tikzstyle{sensor}=[draw, fill=blue!20, text width=8em,&lt;br \/&gt;     text centered, minimum height=2.5em]&lt;br \/&gt;      &#92;tikzstyle{webserver} = [sensor, text width=8em, fill=red!20,&lt;br \/&gt;     minimum height=8em, rounded corners]&lt;br \/&gt;      &#92;tikzstyle{index} = [sensor, text width=8em, fill=green!20,&lt;br \/&gt;     minimum height=8em, rounded corners]&lt;br \/&gt;      &#92;tikzstyle{arduino} = [sensor, fill=blue!20,&lt;br \/&gt;     minimum height=8em, rounded corners]&lt;br \/&gt;      &#92;tikzstyle{d3js} = [sensor, text width=8em, fill=orange!20,&lt;br \/&gt;     minimum height=3em, rounded corners]&lt;br \/&gt;      &#92;tikzstyle{express} = [sensor, minimum width=3em, fill=orange!20,&lt;br \/&gt;     minimum height=3em, rounded corners]&lt;br \/&gt;      &#92;def&#92;blockdist{2.}&lt;br \/&gt; [\/preamble]&lt;br \/&gt;   &#92;node(webserver) [webserver] {&#92;begin{tabular}{c} &#92;textbf{WebServer.js}&#92;&#92;&#92;scriptsize nodeJS based &#92;&#92;&#92;scriptsize   &#92;end{tabular}} ;&lt;br \/&gt;   &#92;path (socket.west)+(-&#92;blockdist,0) node (index) [index] {&#92;textbf{index.html}};&lt;br \/&gt;   &#92;path (index.south) + (0,-0.3) node (d3js) [d3js] {&#92;textbf{d3js}};&lt;br \/&gt;   &#92;path (index.north)+(0,0.5) node (fe) {&#92;begin{tabular}{c} &#92;textbf{frontend}  &#92;&#92;&#92;scriptsize happens in the browser &#92;end{tabular}};&lt;br \/&gt;   &#92;path (webserver.east)+(&#92;blockdist,-0) node (arduino) [arduino] {&#92;begin{tabular}{c} &#92;textbf{WebClient.ino}&#92;&#92;&#92;scriptsize JSON  &#92;&#92;&#92;scriptsize Arduino Sketch &#92;end{tabular}};&lt;br \/&gt;   &#92;path (arduino.north)+(0,0.5) node (fe) {&#92;begin{tabular}{c} &#92;textbf{sensor}  &#92;&#92;&#92;scriptsize happens in the arduino uno &#92;end{tabular}};&lt;br \/&gt;   &#92;path (webserver.south) + (0,-0.3) node (express) [express] {&#92;begin{tabular}{c} &#92;textbf{express.js}&#92;&#92;&#92;scriptsize WebServer &#92;end{tabular}};&lt;br \/&gt;   &#92;path (webserver.north)+(0,0.5) node (be) {&#92;begin{tabular}{c}&#92;textbf{backend} &#92;&#92;&#92;scriptsize happens on the server&#92;end{tabular}};&lt;br \/&gt;   &#92;draw [black, fill=gray!50, fill opacity=0.3, dashed, rounded corners]($(index.north west)+(-10pt,30pt)$)  -- ($(index.north east)+(30pt,30pt)$) -- ($(index.south east)+(30pt,-50pt)$) -- ($(index.south west)+ (-10pt,-50pt)$) -- cycle;&lt;br \/&gt;   &#92;draw [black, fill=gray!50, fill opacity=0.3, dashed, rounded corners]($(arduino.north west)+(-30pt,30pt)$)  -- ($(arduino.north east)+(10pt,30pt)$) -- ($(arduino.south east)+(10pt,-50pt)$) -- ($(arduino.south west)+ (-30pt,-50pt)$) -- cycle;&lt;\/p&gt; &lt;p&gt;&#92;end{tikzpicture}&lt;br \/&gt; \" class=\"latex\" \/><\/p>\n<h2> Der ArduinoSketch <\/h2>\n<p>Der ArduinoSketch hat die Aufgabe eine Serielle Verbindung zum WebServer aufzubauen und<br \/>\ndie (gemessenen) Daten im JSON-Format: {&#8222;time&#8220;: time,&#8220;a0&#8243;:a0,&#8220;a1&#8243;,a1, &#8230; } zu \u00fcbermitteln. Dabei ist das Feld &#8222;time&#8220; unverzichtbar. &#8222;a0&#8220;, &#8222;a1&#8220; und &#8230; sind dann die jeweiligen Messdaten. <\/p>\n<p>[js_markieren]<br \/>\n<input type=\"button\" value=\"Markiere Code\" onClick=\"fnSelect('WebClient')\"><\/p>\n<div id=\"WebClient\" style=\"overflow:auto;height:200px;\">\n<pre lang=\"c\">\r\n\/*\r\n  JSON ubs client\r\n\r\n This sketch sends Data in JSON-Format to a NodeJS WebServer \r\n over usb-link.\r\n\r\n \r\n SensorPins:\r\n * Not implemented jet\r\n \r\n \r\n created 01 Jun 2014\r\n by Wolfgang Wolff\r\n \r\n*\/\r\n \r\n\r\n\/\/ the time is important \r\nint time = 0;\r\n\r\n\/\/ two variables to hold the sensor data\r\ndouble a0 = 0.0; \r\ndouble a1 = 3.0;\r\n\r\nvoid setup(void) {\r\n  pinMode(ledPin, OUTPUT);  \/\/1\r\n  Serial.begin(9600);\r\n  \r\n  digitalWrite(ledPin, LOW);\r\n \r\n}\r\n \r\nvoid loop(void) {     \r\n  \/\/ JSON-Format: {\"time\": time,\"a0\":a0,\"a1\",a1, ... } \r\n  \/\/ important: the filed \"time\" is necessary\r\n  Serial.print(\"{\\\"time\\\":\");\r\n  Serial.print(time);\r\n  Serial.print(\",\\\"a0\\\":\");\r\n  Serial.print(a0);\r\n  Serial.print(\",\\\"a1\\\":\");\r\n  Serial.print(a1);   \r\n  Serial.print(\"}\");\r\n  Serial.println();\r\n  \r\n  \/\/ time to wait before the next dataset is taken:\r\n  delay(5000);\r\n  \/\/ readout sensor data \r\n  \/\/ here using a sin and cos-function to simulate real data\r\n  time = time + 5;\r\n  a0 = 3*sin(time);\r\n  a1 = 2*cos(time); \r\n}\r\n<\/pre>\n<\/div>\n<p><\/br> <\/p>\n<h2> Der WebServer <\/h2>\n<p>Als Basis f\u00fcr den WebServer dient das GitHub Projekt <a href=\"https:\/\/github.com\/billroy\/arduino-livechart\" title=\"arduino-livechart\" target=\"_blank\">arduino-livechart<\/a>. Damit arduino-livechart auf mit der Aktuellen NodeJS Version funktioniert m\u00fcssen im ExpressJS-Code ein paar \u00c4nderungen vorgenommen werden. Diese \u00c4nderungen sind n\u00f6tig, da in der neueren Version von Express Middleware in eigenen Module ausgelagert wurde. <\/p>\n<ul>\n<li>Das Module <a href=\"https:\/\/github.com\/expressjs\/body-parser\" title=\"body-parser\" target=\"_blank\">body-phraser<\/a> ist der Ersatz f\u00fcr die ExpressJS-Funktion: <code>express.bodyParser()<\/code>.<\/li>\n<li>Das Module <a href=\"https:\/\/github.com\/expressjs\/morgan\" title=\"morgan\" target=\"_blank\">morgan<\/a> ist der Ersatz f\u00fcr die ExpressJS-Funktion: <code> express.logger()<\/code><\/li>\n<\/ul>\n<p>Konkret muss in der WebServer.js (in der original Quelle ist das die Datei index.js) der Code<\/p>\n<pre lang=\"js\"> \r\nvar util = require('util');\r\nvar express = require('express');\r\nvar app = express();\r\n\r\napp.configure(function () {\r\n\tapp.use(express.logger());\r\n\tapp.use(express.bodyParser());\r\n});\r\n<\/pre>\n<p>durch <\/p>\n<pre lang=js>\r\nvar util = require('util');\r\nvar express = require('express');\r\nvar app = express();\r\nvar bodyParser = require('body-parser');\r\n\r\n\r\nvar env = process.env.NODE_ENV || 'development';\r\nif ('development' == env) {\r\n   app.use(require('morgan')('dev'));\r\n\t app.use(bodyParser());\r\n}\r\n<\/pre>\n<p>ersetzt werden. Damit alle Abh\u00e4ngigkeiten installiert werden k\u00f6nnen muss noch die Datei <em>package.json<\/em> um die fehlenden Module erg\u00e4nzt werden:<\/p>\n<pre>\r\n{\r\n\t\"name\": \"arduino-livechart\",\r\n\t\"version\": \"0.0.1\",\r\n\t\"private\": true,\r\n\t\"author\": \"Bill Roy <bill@bitlash.net>\",\r\n\t\"description\": \"Collects data from a USB- or network-connected Arduino and displays it as a D3 graph\",\r\n\t\"dependencies\": {\r\n\t\t\"optimist\": \">=0.3.5\",\r\n\t\t\"express\": \">=3.0.3\",\r\n\t\t\"shelljs\": \">=0.0.8\",\r\n\t\t\"serialport\": \">=1.1.0\",\r\n\t\t\"body-parser\": \">=1.3.0\",\r\n\t\t\"morgan\": \">=1.0.0\"\r\n\t},\r\n\t\"engines\": {\r\n\t\t\"node\": \">=0.10.1\",\r\n\t\t\"npm\": \"1.1.x\"\r\n\t}\r\n}\r\n<\/pre>\n<p><\/br><br \/>\nDer Befehl<br \/>\n<code>npm install<\/code><br \/>\ninstalliert alle Module im Ordner node_modules. Jetzt ist der WebServer bereit f\u00fcr den Einsatz.<\/p>\n<h2> Das Frontend: index.html<\/h2>\n<p>Am Frontend habe ich bisher keine Ver\u00e4nderungen vorgenommen. <\/p>\n<h2> Das Starten der App <\/h2>\n<ol>\n<li>Zuerst solle der Arduino-Sketch auf den Arduino Uno aufgespielt werden. Der Arduino sollte mit USB-Kabel mit dem PC verbunden ein und zus\u00e4tzlich mit dem lokalen Netzwerk per EthernetShield verbunden sein. <\/li>\n<li>Dann sollte der Node-WebServer gestartet werde:<br \/>\n<code><br \/>\nnode WebServer.js<br \/>\n<\/code> <\/li>\n<li>Jetzt kann \u00fcber die URL http:\/\/localhost:8080 auf den WebServer zugegriffen werden. Wenn alles funktioniert sieht der Inhalt der WebSeite wie folgt aus:<\/li>\n<p><img src=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2014\/06\/sample-chart.png\" alt=\"\" \/><\/p>\n<\/ol>\n<h2> Was noch zu tun ist <\/h2>\n<p>Viel, aber zuerst muss ich erst einmal noch etwas besser d3js lernen.<br \/>\nDenkbar w\u00e4re dieses Projekt mit Hilfe eines Wetter-Sensoren (Temperatur,Druck,Feuchte) zu einer Wetterstation auszubauen. Dazu muss aber der ArduinoSketch und das Frontend entsprechend erweitert werden.     <\/p>\n<h2>Quellen:<\/h2>\n<ul>\n<li><a href=\"https:\/\/github.com\/billroy\/arduino-livechart\" title=\"arduino-livechart\" target=\"_blank\">arduino-livechart<\/a><\/li>\n<li><a href=\"https:\/\/blog.mayflower.de\/2545-Nummer-5-lebt!-Oder-wie-mein-Arduino-Board-mit-JavaScript-gesteuert-werden-kann.html\" title=\"Nummer 5 lebt! Oder wie mein Arduino Board mit JavaScript gesteuert werden kann\" target=\"_blank\">Nummer 5 lebt! Oder wie mein Arduino Board mit JavaScript gesteuert werden kann<\/a><\/li>\n<li><a href=\"http:\/\/bocoup.com\/weblog\/javascript-arduino-programming-with-nodejs\/\" title=\"JavaScript: Arduino Programming on Node.js\" target=\"_blank\">JavaScript: Arduino Programming on Node.js<\/a><\/li>\n<li><a href=\"http:\/\/www.schillmania.com\/projects\/arduino-js\/\" title=\"JavaScript-based Arduino Uno communication\" target=\"_blank\">JavaScript-based Arduino Uno communication<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/rwaldron\/idiomatic.js\" title=\"Principles of Writing Consistent, Idiomatic JavaScript\" target=\"_blank\">Principles of Writing Consistent, Idiomatic JavaScript<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Zusammenfassung In diesem Beitrag soll erkl\u00e4rt werden, wie mit einem Arduino Uno Daten erfasst werden und mittels JSON an einen WebServer \u00fcbermittelt werden k\u00f6nnen. Mit Hilfe von NodeJS wird ein WebSever aufgebaut, der die vom Arduino \u00fcbermittelten Daten verarbeitet und in einem Diagramm dargestellt. Ich verwende dazu das GitHub Projekt arduino-livechart, bei dem (da in &hellip; <a href=\"http:\/\/blog.herrwolff.org\/?p=1545\" class=\"more-link\"><span class=\"screen-reader-text\">Arduino &#8212; Datenvisualisierung mit NodeJS<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"spay_email":"","jetpack_publicize_message":""},"categories":[26,5,13,32,24,16],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p1ZaWF-oV","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=\/wp\/v2\/posts\/1545"}],"collection":[{"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1545"}],"version-history":[{"count":101,"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=\/wp\/v2\/posts\/1545\/revisions"}],"predecessor-version":[{"id":1788,"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=\/wp\/v2\/posts\/1545\/revisions\/1788"}],"wp:attachment":[{"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1545"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}