2018-11-09, 01:19 PM
(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.