// Demo: NMEA2000 library. Send main cabin temperature to the bus.
#include <Arduino.h>
#include <NMEA2000_CAN.h> // This will automatically choose right CAN library and create suitable NMEA2000 object
#include <N2kMessages.h>
// List here messages your device will transmit.
const unsigned long TransmitMessages[] PROGMEM={130310L,130311L,130312L,0};
void setup() {
// Set Product information
NMEA2000.SetProductInformation("00000001", // Manufacturer's Model serial code
100, // Manufacturer's product code
"Simple temp monitor", // Manufacturer's Model ID
"1.1.0.21 (2016-12-31)", // Manufacturer's Software version code
"1.1.0.0 (2016-12-31)" // Manufacturer's Model version
);
// Set device information
NMEA2000.SetDeviceInformation(112233, // Unique number. Use e.g. Serial number.
130, // Device function=Temperature. See codes on http://www.nmea.org/...odes v 2.00.pdf
75, // Device class=Sensor Communication Interface. See codes on http://www.nmea.org/...odes v 2.00.pdf
2040 // Just choosen free from code list on http://www.nmea.org/...ration list.pdf
);
// Uncomment 2 rows below to see, what device will send to bus. Use e.g. OpenSkipper or Actisense NMEA Reader
//Serial.begin(115200);
//NMEA2000.SetForwardStream(&Serial);
// If you want to use simple ascii monitor like Arduino Serial Monitor, uncomment next line
//NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); // Show in clear text. Leave uncommented for default Actisense format.
// If you also want to see all traffic on the bus use N2km_ListenAndNode instead of N2km_NodeOnly below
NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly,22);
//NMEA2000.SetDebugMode(tNMEA2000::dm_Actisense); // Uncomment this, so you can test code without CAN bus chips on Arduino Mega
NMEA2000.EnableForward(false); // Disable all msg forwarding to USB (=Serial)
// Here we tell library, which PGNs we transmit
NMEA2000.ExtendTransmitMessages(TransmitMessages);
NMEA2000.Open();
}
void loop() {
SendN2kTemperature();
NMEA2000.ParseMessages();
}
double ReadCabinTemp() {
return CToKelvin(22.5); // Read here the true temperature e.g. from analog input
}
double ReadWaterTemp() {
return CToKelvin(15.5); // Read here the true temperature e.g. from analog input
}
#define TempUpdatePeriod 2500
//J2K100
double EngineSpeed=5000 ;
double EngineBoostPressure=50 ;
int8_t EngineTiltTrim=15 ;
/*
unsigned char EngineInstance=0 ;//
double EngineOilPress=3 ; //PAS
double EngineOilTemp=50 ; //KEL
double EngineCoolantTemp=10 ; //KEL
double AltenatorVoltage=28 ; //V
double FuelRate=10 ; //GPH
double EngineHours=1100 ; //SEC
double EngineCoolantPress=10 ; //PAS
double EngineFuelPress=11 ; // PAS
int8_t EngineLoad=50 ; //%
int8_t EngineTorque=50 ; //%
bool flagCheckEngine=1 ; //ON/OFF
bool flagOverTemp=0 ;
bool flagLowOilPress=0 ;
bool flagLowOilLevel=0 ;
bool flagLowFuelPress=0 ;
bool flagLowSystemVoltage=0 ;
bool flagLowCoolantLevel=0 ;
bool flagWaterFlow=1 ;
bool flagWaterInFuel=1 ;
bool flagChargeIndicator=1 ;
bool flagPreheatIndicator=0 ;
bool flagHighBoostPress=0 ;
bool flagRevLimitExceeded=0 ;
bool flagEgrSystem=0 ;
bool flagTPS=0 ;
bool flagEmergencyStopMode=0 ;
bool flagWarning1=0 ;
bool flagWarning2=0 ;
bool flagPowerReduction=0 ;
bool flagMaintenanceNeeded=0 ;
bool flagEngineCommError=0 ;
bool flagSubThrottle=0 ;
bool flagNeutralStartProtect=0 ;
bool flagEngineShuttingDown=0
*/
void SendN2kTemperature() {
static unsigned long TempUpdated=millis();
tN2kMsg N2kMsg;
if ( TempUpdated+TempUpdatePeriod<millis() ) {
TempUpdated=millis();
SetN2kEngineParamRapid(N2kMsg, 0, EngineSpeed,
EngineBoostPressure, EngineTiltTrim);
NMEA2000.SendMsg(N2kMsg);
SetN2kEngineDynamicParam(N2kMsg, 0, 300000, 100+273, 90+273, 28,
10, 1100,10 ,11 ,50 ,50,
1,0, 0, 0, 0, 0, 0,1, 0, 1, 0, 0,0,0,0, 0, 0,0,0,0,0,0,0,0) ;
NMEA2000.SendMsg(N2kMsg);
//*/
SetN2kTemperature(N2kMsg, 1, 1, N2kts_MainCabinTemperature, ReadCabinTemp());
NMEA2000.SendMsg(N2kMsg);
SetN2kEnvironmentalParameters(N2kMsg, 1, N2kts_MainCabinTemperature, ReadCabinTemp());
NMEA2000.SendMsg(N2kMsg);
SetN2kOutsideEnvironmentalParameters(N2kMsg, 1, ReadWaterTemp());
NMEA2000.SendMsg(N2kMsg);
Serial.print(millis()); Serial.println(", Temperature send ready");
}
}