2019-01-21, 08:46 PM
Sending data ... IMO Everything can be routed to SK Some data is best sent as NMEA ie gps, Wind to allow OCPN or other apps pypilot. But in the end it should be in SignalK. Other MCU's Make it possible to extend this.I have had issues with Node-Red but that was a while ago. That said I think NodeRed Rocks displaying data and is very easy to interface with SignalK. I had Problems with resources, stability, and lag.
Mission critical stuff needs to be tested.
Here are a few crude methods of writing and read data to SK and NMEA.
Reading all the docs helps:}
I am not a very skilled coder but I can make it work.
The difference with boats from IOT is most of time we are reading and reacting to data is much faster.
Your house does not move.
Also your life/comfort of your crew may depend on boat systems working properly...
and yet another example of getting 1 key value for a esp32 via wifi.
Mission critical stuff needs to be tested.
Here are a few crude methods of writing and read data to SK and NMEA.
Reading all the docs helps:}
I am not a very skilled coder but I can make it work.
The difference with boats from IOT is most of time we are reading and reacting to data is much faster.
Your house does not move.
Also your life/comfort of your crew may depend on boat systems working properly...
Code:
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
SignalK = '{"updates":[{"$source":"OPserial.epsolar","timestamp":"'+str(timestamp)+'","values":['
SignalK += ',{"path": "electrical.solar.'+str(unitid)+'.controllerMode","value":"'+str(schgmode)+'"}'
SignalK += ',{"path": "electrical.batteries.'+str(unitid)+'.temperature","value":'+str(batTemp)+'}'
SignalK += ',{"path": "electrical.batteries.'+str(unitid)+'.temperature.faultUpper","value":'+str(batwarnupperTemp)+'}'
SignalK += ',{"path": "electrical.batteries.'+str(unitid)+'.temperature.faultLower","value":'+str(batwarnlowerTemp)+'}'
SignalK += ',{"path": "electrical.batteries.'+str(unitid)+'.capacity.stateOfCharge","value":'+str(soc)+'}'
SignalK += ']}]}\n'
sock.sendto(SignalK, ('localhost', 55559))
Code:
char buf3 [128];
snprintf(buf3, sizeof buf3, "{\"updates\":[{ \"$source\": \"OPwifi.masthead\",\"values\":[{\"path\": \"navigation.lights\",\"value\":\"%s\" }]}]}\n", lightstate);
udp.beginPacket(udpAddress, 55561);
udp.printf(buf3);
Serial.println(buf3);
udp.endPacket();
Code:
if (dt >= 1000) { // output every 1s
last_time += 1000;
if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
//WiFiClient client;
HTTPClient http;
http.begin("http://192.168.1.7:3000/signalk/v1/api/vessels/self/sensors/anchorLight"); //Specify the URL
int httpCode = http.GET(); //Make the request
char lightstate[10];
if (httpCode > 0) { //Check for the returning code
String payload = http.getString();
StaticJsonBuffer<500> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(payload);
http.end(); //Free the resources
int light = root["value"];
//Serial.println(light);
if (light == lastlight) {
return;
}
if (light == 1) {
digitalWrite (ALT_PIN, HIGH); // turn on the LED
lastlight = light;
// Serial.println(light);
//lights = "anchored";
strcpy(lightstate, "anchored");
} else if (light == 0) {
digitalWrite (ALT_PIN, LOW); // turn off the LED
lastlight = light;
//lights = "Off";
strcpy(lightstate, "Off");
} else {
Serial.println("Fail");
}
//http.end(); //Free the resources
//return;
} else {
Serial.println("get http failed");
}