Created
January 14, 2021 15:01
-
-
Save mairas/f63a22e56045ebc637cd9b164a63b6fa to your computer and use it in GitHub Desktop.
NMEA 2000 output from SensESP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// wire up a DS18B20 (OneWire device) | |
DallasTemperatureSensors* dts = new DallasTemperatureSensors(ONEWIRE_DQ_PIN); | |
uint onewire_read_delay = 500; | |
auto* onewire_temp = | |
new OneWireTemperature(dts, onewire_read_delay, "/temperature/oneWire"); | |
onewire_temp->connect_to( | |
new SKOutputNumber("onewire.temperature", "/temperature/skPath")); | |
// output the temperatures read by DS18B20 also on NMEA 2000 | |
// Reserve enough buffer for sending all messages. This does not work on small | |
// memory devices like Uno or Mega | |
NMEA2000.SetN2kCANSendFrameBufSize(250); | |
// Set Product information | |
NMEA2000.SetProductInformation( | |
"20200112", // Manufacturer's Model serial code | |
101, // Manufacturer's product code | |
"SH-ESP32 Sender", // Manufacturer's Model ID | |
"0.1.0.1 (2020-01-12)", // Manufacturer's Software version code | |
"0.0.2.0 (2020-01-12)" // Manufacturer's Model version | |
); | |
// Set device information | |
NMEA2000.SetDeviceInformation( | |
1, // Unique number. Use e.g. Serial number. | |
132, // Device function=Analog to NMEA 2000 Gateway. See codes on | |
// http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf | |
25, // Device class=Inter/Intranetwork Device. See codes on | |
// http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf | |
2046 // Just choosen free from code list on | |
// http://www.nmea.org/Assets/20121020%20nmea%202000%20registration%20list.pdf | |
); | |
NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly, 22); | |
NMEA2000.EnableForward(false); // Disable all msg forwarding to USB (=Serial) | |
NMEA2000.Open(); | |
// No need to parse the messages at every single loop iteration; 1 ms will do | |
app.onRepeat(1, []() { NMEA2000.ParseMessages(); }); | |
auto* can_output = new LambdaConsumer<float>([](float input) -> void { | |
tN2kMsg N2kMsg; | |
SetN2kTemperatureExt(N2kMsg, 1, 1, N2kts_MainCabinTemperature, input, | |
input); | |
NMEA2000.SendMsg(N2kMsg); | |
}); | |
// connect the temperature input to N2K output | |
onewire_temp->connect_to(can_output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment