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
#5
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...
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();
and yet another example of getting 1 key value for a esp32 via wifi.

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");
     }
Reply


Messages In This Thread
RE: Also send I2C sensor data to Node-Red so ALL instruments show on the dashboard - by ddelorme - 2019-01-21, 08:46 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)