This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Also send I2C sensor data to Node-Red so ALL instruments show on the dashboard
#4
(2018-11-08, 01:59 PM)jim321 Wrote: example import clipboard  opencpn is limited to a few things it can display you can use dashboard in NR

Code:
[{"id":"d75f9eeb.e9af2","type":"websocket in","z":"82321e4.b0af8e","name":"ws","server":"41d6b650.f16a38","client":"","x":50,"y":620,"wires":[["83969d8.a84d66","c5c9eb43.d8f238","38780251.f951ae","ba58bc65.7efb9","e81cb99d.1966d8"]]},{"id":"83969d8.a84d66","type":"jsonpath","z":"82321e4.b0af8e","expression":"$.updates..values[*]","split":false,"name":"Signal K delta values","x":240,"y":620,"wires":[["770e578d.94a6d8"]]},{"id":"770e578d.94a6d8","type":"function","z":"82321e4.b0af8e","name":"merge values","func":"var paths={};\nvar arrayLength = msg.payload.length;\nfor (var i = 0; i < arrayLength; i++) {\n    paths[msg.payload[i].path]=msg.payload[i].value;\n}\nmsg.payload = paths;\nreturn msg;","outputs":1,"noerr":0,"x":440,"y":620,"wires":[["abaad182.6b541","4647605c.f27e1","94c51894.715fe8","b2490678.59dba8","a2c7a150.6c2af","963a6ecd.eb9f2","b1b1f8ee.678498","8e6844de.9733a8","28f5b60f.9eb77a","1d6e8fe5.f399d","4b42071a.e35c88","a26efae0.3bb758","ec450371.3822a"]]},{"id":"11507251.ffafbe","type":"ui_template","z":"82321e4.b0af8e","group":"1e14c235.4fc26e","name":"Tempin","order":3,"width":"3","height":"6","format":"<script src=\"/myjs/tween-min.js\"></script>\n<script src=\"/myjs/steelseries-min.js\"></script>\n<script>\nvar tempout;\n    (function(scope){ \n        scope.$watch('msg', function(msg) {\n           if (typeof(msg.value) != \"undefined\") tempout.setValueAnimated(msg.value);\n           //if (typeof(msg.threshold) != \"undefined\") radial4.setThreshold(msg.threshold);\n          // if (typeof(msg.odo) != \"undefined\")radial4.setOdoValue(msg.odo);  \n           //if (typeof(msg.userLed) != \"undefined\") radial4.setUserLedOnOff(msg.userLed);  \n          // if (typeof(msg.trend) != \"undefined\")\n            {\n               // if (msg.trend==1)     radial4.setTrend(steelseries.TrendState.UP);\n                //if (msg.trend==0)     radial4.setTrend(steelseries.TrendState.STEADY);\n               // if (msg.trend==-1)    radial4.setTrend(steelseries.TrendState.DOWN);\n               // if (msg.trend==-2)    radial4.setTrend(steelseries.TrendState.OFF);\n            }\n        });\n    })(scope);\n\n    var sections = [steelseries.Section(0, 25, 'rgba(0, 0, 220, 0.3)'),\n                        steelseries.Section(25, 50, 'rgba(0, 220, 0, 0.3)'),\n                        steelseries.Section(50, 75, 'rgba(220, 220, 0, 0.3)') ],\n\n            // Define one area\n    areas = [steelseries.Section(75, 100, 'rgba(220, 0, 0, 0.3)')],\n\n    tempout = new steelseries.Linear('tempout', {\n            gaugeType: steelseries.GaugeType.TYPE2,\n            width: 140,\n            height: 300,\n            //size: 292,\n            section: sections,\n            area: areas,\n            titleString: \"Inside\",\n            unitString: \"Degrees F\",\n            threshold: 80,\n            lcdVisible: true,\n           \n            //thresholdRising: false,\n           // userLedVisible: true,\n           // useOdometer: true,\n          //  lcdVisible: true,\n           // trendVisible: true\n        });\n                        \n    tempout.setFrameDesign(steelseries.FrameDesign.BRASS);\n    tempout.setValueAnimated(0);\n    tempout.setPointerType(steelseries.PointerType.TYPE9);\n   // radial4.setThreshold(50);\n    //radial4.blinkUserLed(0);\n   // radial4.setOdoValue(0);\n\n\n</script>\n\n<canvas id=\"tempout\" width=\"140\" height=\"300\"></canvas>\n","storeOutMessages":true,"fwdInMessages":true,"x":1198.0003967285156,"y":588.0000686645508,"wires":[[]]},{"id":"28f5b60f.9eb77a","type":"function","z":"82321e4.b0af8e","name":"Water Temp","func":"var signalk_key=\"environment.water.temperature\";\n\nif(msg.payload.hasOwnProperty(signalk_key)){\n    msg.payload=msg.payload[signalk_key];\n    return msg;\n    \n\n}","outputs":1,"noerr":0,"x":639,"y":563.000002861023,"wires":[["ece38a60.7f99c8"]]},{"id":"ee83bd35.bdac9","type":"function","z":"82321e4.b0af8e","name":"","func":"msg.value=msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":976.000057220459,"y":588.0000066757202,"wires":[["11507251.ffafbe"]]},{"id":"ece38a60.7f99c8","type":"function","z":"82321e4.b0af8e","name":"K to F","func":"var temp = msg.payload;\n\nvalue = (temp * 9.0) / 5.0 - 459.67; \nmsg.payload=value;\nreturn msg; ","outputs":1,"noerr":0,"x":779,"y":563.000002861023,"wires":[[]]},{"id":"1d6e8fe5.f399d","type":"function","z":"82321e4.b0af8e","name":"cabin pres","func":"var signalk_key=\"environment.outside.pressure\";\n\nif(msg.payload.hasOwnProperty(signalk_key)){\n    msg.payload=msg.payload[signalk_key];\n    return msg;\n    \n\n}","outputs":1,"noerr":0,"x":639,"y":603.000002861023,"wires":[["cffed0ba.ba82b"]]},{"id":"cffed0ba.ba82b","type":"ui_chart","z":"82321e4.b0af8e","name":"","group":"1e14c235.4fc26e","order":2,"width":0,"height":0,"label":"cabin pres","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"604800","cutout":0,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"x":799,"y":603.000002861023,"wires":[[],[]]},{"id":"4b42071a.e35c88","type":"function","z":"82321e4.b0af8e","name":"cabin temp","func":"var signalk_key=\"environment.inside.mainCabin.temperature\";\n\nif(msg.payload.hasOwnProperty(signalk_key)){\n    msg.payload=msg.payload[signalk_key];\n    return msg;\n    \n\n}","outputs":1,"noerr":0,"x":639,"y":643.000002861023,"wires":[["ee81c52e.60bd18"]]},{"id":"5f3ba447.cc53ec","type":"ui_chart","z":"82321e4.b0af8e","name":"cabin temp","group":"1e14c235.4fc26e","order":1,"width":0,"height":0,"label":"cabin temp","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"x":1075.1666870117188,"y":643.0000114440918,"wires":[[],[]]},{"id":"ee81c52e.60bd18","type":"function","z":"82321e4.b0af8e","name":"K to F","func":"var temp = msg.payload;\n\nvalue = (temp * 9.0) / 5.0 - 459.67; \nmsg.payload=value;\nreturn msg; ","outputs":1,"noerr":0,"x":781,"y":643.3333387374878,"wires":[["5f3ba447.cc53ec","ee83bd35.bdac9"]]},{"id":"a26efae0.3bb758","type":"function","z":"82321e4.b0af8e","name":"float","func":"var signalk_key=\"sensors.floatswitch\";\n\nif(msg.payload.hasOwnProperty(signalk_key)){\n    msg.payload=msg.payload[signalk_key];\n    return msg;\n    \n\n}","outputs":1,"noerr":0,"x":630,"y":681,"wires":[["c19bf413.43a098"]]},{"id":"41d6b650.f16a38","type":"websocket-listener","z":"","path":"ws://localhost:3000/signalk/v1/stream","wholemsg":"false"},{"id":"1e14c235.4fc26e","type":"ui_group","z":"","name":"ENVIRONMENT","tab":"8b452ef1.b3d38","order":1,"disp":true,"width":"6"},{"id":"8b452ef1.b3d38","type":"ui_tab","z":"","name":"Tab 2","icon":"dashboard","order":2}]
[*]

This is working!! I can't believe it!!

Thanks for that, and sorry for the slow answer, we were out at sea with no internet. Then when I saw the block of code, I had no idea what I was supposed to do with it and didn't want to answer with a stupid post so I read some Node-Red documentation before then imported your code Smile

I played around with it a bit and this is very much straightforward and easy to use once I saw a working example, I wish this was in the docs, it would have saved me a lot of time, you're amazing, friend! I'm loving Node-Red so far and will play with it a lot more, especially now that I know we can just poll the Signal K server like this hehe.

(2018-11-09, 01:19 PM)PaddyB Wrote:
(2018-11-07, 03:31 PM)NaturalBornCamper Wrote: So anyways, I managed to make our analog oil pressure sensors work with an Arduino Uno board I had lying around and send it over I2C to OpenPlotter, until I realized that you can only add sensors that were pre-configured in OpenPlotter, 

You can send the data direct to signalk over serial from the arduino, like this - 
Code:
#include "ArduinoJson.h"
int LED_pin = 2;


void setup() {
 // put your setup code here, to run once:
 Serial.begin(4800);

// Serial.println("Starting Up, Please Wait...");
 // initialize digital pin LED_BUILTIN as an output.
 pinMode(LED_pin, OUTPUT);
}

void loop() {
 // put your main code here, to run repeatedly:

 int randon_num = random(1, 300);
 sendSigK("mytest.test.test", randon_num);
 
 int state = digitalRead(LED_pin);
 digitalWrite(LED_pin, !state);
 delay(2000);

}



void sendSigK(String sigKey, float data) {    //    send SigK


 DynamicJsonBuffer jsonBuffer;
 String deltaText;

 //  build delta message
 JsonObject& delta = jsonBuffer.createObject();

 //updated array
 JsonArray& updatesArr = delta.createNestedArray("updates");
 JsonObject& thisUpdate = updatesArr.createNestedObject();   //Json Object nested inside delta [...
 JsonArray& values = thisUpdate.createNestedArray("values"); // Values array nested in delta[ values....
 JsonObject& thisValue = values.createNestedObject();
 thisValue["path"] = sigKey;
 thisValue["value"] = data;

 thisUpdate["Source"] = "ESP11";
 delta.printTo(Serial);
 Serial.println();
}

Then you need to add this to   /home/pi/.signalk/settings.json - underneath the lines >
 },
  "loggingDirectory": "/home/pi/Logs",
  "mdns": false,
  "pipedProviders": [
Code:
{
      "enabled": true,
     "id": "nmeaFromFile",
     "pipeElements": [
       {
         "type": "providers/serialport",
         "options": {
           "device": "/dev/ttyUSB2",
           "baudrate": 4800,
           "toStdout": ["nmea0183out1", "nmea0183out2"]
         },
         "optionMappings": [
           {
             "fromAppProperty": "argv.nmeadevice",
             "toOption": "device"
           },

           {
             "fromAppProperty": "argv.nmeabaudrate",
             "toOption": "baudrate"
           }
         ]
       },
       {
         "type": "providers/from_json",
         "options": {
           "sentenceEvent": "nmea0183in1"
         },
         "optionMappings": [
           {
             "fromAppProperty": "selfId",
             "toOption": "selfId"
           },
           {
             "fromAppProperty": "selfType",
             "toOption": "selfType"
           }
         ]
       }
     ]
   },

Then it should be added as signalk. Opencpn only see NMEA data so you'll need to convert it to NMEA it you want to see the data in that prog.

Thanks for that!

I ended up using Node-Red and all is well, however I didn't know you could inject json into signal K like this, it would have saved me a lot of headaches if I had know it was possible before. I will definitely refer to your code as I am getting some serial data from another pin that I read in Python and I need to send it over to Signal K, so I'll very possibly be using this method!!
Reply


Messages In This Thread
RE: Also send I2C sensor data to Node-Red so ALL instruments show on the dashboard - by NaturalBornCamper - 2018-11-18, 11:34 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)