Remote DATV station parameters monitoring (PART 4)

Integrating in Main Sketch

//########### FOR THE HC-12 RF TRANSCEIVER MODULE #################################################################
#include <SoftwareSerial.h>;
#define RX 2 //Connect to the TX pin of the HC-12
#define TX 3 //Connect to the RX pin of the HC-12
SoftwareSerial HC12_Serial(RX, TX);


//############ FOR THE ONE WIRE DALLAS TEMPERATURE SENSORS #########################################################
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wires of both sensors are connected to port 8 on the Arduino
#define ONE_WIRE_BUS 4
#define TEMPERATURE_PRECISION 9

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature Dallas_temperature_sensors(&oneWire);

// arrays to hold device addresses
DeviceAddress Ambient_Air_Temperature_Sensor = { 0x28, 0x2A, 0x6B, 0x96, 0xF0, 0x01, 0x3C, 0xBA };
DeviceAddress Heatsink_Temperature_Sensor   = { 0x28, 0x9B, 0xDE, 0x19, 0x00, 0x00, 0x00, 0x00 };

//############ FOR THE INA226 CURRENT & VOLTAGE MEASURING MODULE #################################################
#include <Wire.h>
#include <INA226_WE.h>
INA226_WE ina226 = INA226_WE(0x40);

//############ DEFINITIONS #######################################################################################
String packet;
int temperature_ambient;
int temperature_heatsink;
int temperature_other;
int voltage_5V_Line;
int amperage_5V_Line;
int voltage_12V_Line;
int amperage_12V_Line;
int voltage_28V_Line;
int amperage_28V_Line;
int PTT_Relay_status;
int other_parameter_1;
int other_parameter_2;
int other_parameter_3;

//############ SETUP ##############################################################################################

void setup() {
  Serial.begin(115200);    // just for monitoring on console

  // START TRANSCEIVER
  HC12_Serial.begin(9600); // this will coresspond to a wireless transmission in the air of 15,000bps
  // higher baud rate would reduce the communication distance

  // START TEMPERATURE SENSORS
  Dallas_temperature_sensors.begin();
  // check if senosrs are on line (for debufgging purposes only)
  if (!Dallas_temperature_sensors.getAddress(Ambient_Air_Temperature_Sensor, 0)) Serial.println("Unable to find address for Device 0");
  if (!Dallas_temperature_sensors.getAddress(Heatsink_Temperature_Sensor, 1)) Serial.println("Unable to find address for Device 1");
  // set the resolution to 12 bit per device
  Dallas_temperature_sensors.setResolution(Ambient_Air_Temperature_Sensor, TEMPERATURE_PRECISION);
  Dallas_temperature_sensors.setResolution(Heatsink_Temperature_Sensor, TEMPERATURE_PRECISION);

  // START INA226 MODULE
  Wire.begin();
  ina226.init();
  ina226.setAverage(AVERAGE_128);
  ina226.setConversionTime(CONV_TIME_1100);
  ina226.setMeasureMode(CONTINUOUS);
  ina226.setResistorRange(0.002, 20.0);
  ina226.setCorrectionFactor(1.031); // defined through calibration
}


//############ ENDLESS LOOP ########################################################################################
void loop() { // run over and over
  // Assigning to the  variables
  Dallas_temperature_sensors.requestTemperatures();
  temperature_ambient = 10 * (get_temp_from_Sensor(Ambient_Air_Temperature_Sensor));
  temperature_heatsink = 10 * (get_temp_from_Sensor(Heatsink_Temperature_Sensor));

  float shuntVoltage_mV = 0.0;
  float loadVoltage_V = 0.0;
  float busVoltage_V = 0.0;
  voltage_28V_Line = 0;
  amperage_28V_Line = 0;
  ina226.readAndClearFlags();
  shuntVoltage_mV = ina226.getShuntVoltage_mV();
  Serial.println(shuntVoltage_mV);
  if (!ina226.overflow) {
    busVoltage_V = ina226.getBusVoltage_V();
    amperage_28V_Line = ina226.getCurrent_mA() / 100;
    voltage_28V_Line  = (busVoltage_V + (shuntVoltage_mV / 1000)) * 10;
  }
  // Assigning  values for the other variables
  temperature_other = 999;
  voltage_5V_Line = 888;
  amperage_5V_Line = 777;
  voltage_12V_Line = 666;
  amperage_12V_Line = 555;
  other_parameter_1 = 444;
  other_parameter_2 = 333;
  other_parameter_3 = 222;
  PTT_Relay_status = 111;

  // Contructing packet with delimiters
  packet = "X|" + String(temperature_ambient) + "|";
  packet = packet + String(temperature_heatsink) + "|";
  packet = packet + String(voltage_28V_Line) + "|";
  packet = packet + String(amperage_28V_Line) + "|";
  packet = packet + String(temperature_other) + "|";
  packet = packet + String(voltage_5V_Line) + "|";
  packet = packet + String(amperage_5V_Line) + "|";
  packet = packet + String(voltage_12V_Line) + "|";
  packet = packet + String(amperage_12V_Line) + "|";
  packet = packet + String(other_parameter_1) + "|";
  packet = packet + String(other_parameter_2) + "|";
  packet = packet + String(other_parameter_3) + "|";
  packet = packet + String(PTT_Relay_status) + "|";
  packet = packet + "X\n";

  Serial.print("Sending Packet "); Serial.println(packet);
  HC12_Serial.print(packet);
  delay(500);  // packet intervals in ms, will be shortened at a later stage
}


//############ FUNCTIONS ########################################################################################

// function to return temperature values
float get_temp_from_Sensor(DeviceAddress deviceAddress)
{
  float tempC = Dallas_temperature_sensors.getTempC(deviceAddress);

  if (tempC == DEVICE_DISCONNECTED_C)
  {
    Serial.println("Error: Could not read temperature data");
    return 0;
  }
  return tempC;
}






//########### FOR THE HC-12 RF TRANSCEIVER MODULE #################################################################
#include <SoftwareSerial.h>;
#define RX 2 //Connect to the TX pin of the HC-12
#define TX 3 //Connect to the RX pin of the HC-12
SoftwareSerial HC12_Serial(RX, TX);


//############ FOR THE ONE WIRE DALLAS TEMPERATURE SENSORS #########################################################
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wires of both sensors are connected to port 8 on the Arduino
#define ONE_WIRE_BUS 4
#define TEMPERATURE_PRECISION 9

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature Dallas_temperature_sensors(&oneWire);

// arrays to hold device addresses
DeviceAddress Ambient_Air_Temperature_Sensor = { 0x28, 0x2A, 0x6B, 0x96, 0xF0, 0x01, 0x3C, 0xBA };
DeviceAddress Heatsink_Temperature_Sensor   = { 0x28, 0x9B, 0xDE, 0x19, 0x00, 0x00, 0x00, 0x00 };

//############ FOR THE INA226 CURRENT & VOLTAGE MEASURING MODULE #################################################
#include <Wire.h>
#include <INA226_WE.h>
INA226_WE ina226 = INA226_WE(0x40);

//############ DEFINITIONS #######################################################################################
String packet;
int temperature_ambient;
int temperature_heatsink;
int temperature_other;
int voltage_5V_Line;
int amperage_5V_Line;
int voltage_12V_Line;
int amperage_12V_Line;
int voltage_28V_Line;
int amperage_28V_Line;
int PTT_Relay_status;
int other_parameter_1;
int other_parameter_2;
int other_parameter_3;

//############ SETUP ##############################################################################################

void setup() {
  Serial.begin(115200);    // just for monitoring on console

  // START TRANSCEIVER
  HC12_Serial.begin(9600); // this will coresspond to a wireless transmission in the air of 15,000bps
  // higher baud rate would reduce the communication distance

  // START TEMPERATURE SENSORS
  Dallas_temperature_sensors.begin();
  // check if senosrs are on line (for debufgging purposes only)
  if (!Dallas_temperature_sensors.getAddress(Ambient_Air_Temperature_Sensor, 0)) Serial.println("Unable to find address for Device 0");
  if (!Dallas_temperature_sensors.getAddress(Heatsink_Temperature_Sensor, 1)) Serial.println("Unable to find address for Device 1");
  // set the resolution to 12 bit per device
  Dallas_temperature_sensors.setResolution(Ambient_Air_Temperature_Sensor, TEMPERATURE_PRECISION);
  Dallas_temperature_sensors.setResolution(Heatsink_Temperature_Sensor, TEMPERATURE_PRECISION);

  // START INA226 MODULE
  Wire.begin();
  ina226.init();
  ina226.setAverage(AVERAGE_128);
  ina226.setConversionTime(CONV_TIME_1100);
  ina226.setMeasureMode(CONTINUOUS);
  ina226.setResistorRange(0.002, 20.0);
  ina226.setCorrectionFactor(1.031); // defined through calibration
}


//############ ENDLESS LOOP ########################################################################################
void loop() { // run over and over
  // Assigning to the  variables
  Dallas_temperature_sensors.requestTemperatures();
  temperature_ambient = 10 * (get_temp_from_Sensor(Ambient_Air_Temperature_Sensor));
  temperature_heatsink = 10 * (get_temp_from_Sensor(Heatsink_Temperature_Sensor));

  float shuntVoltage_mV = 0.0;
  float loadVoltage_V = 0.0;
  float busVoltage_V = 0.0;
  voltage_28V_Line = 0;
  amperage_28V_Line = 0;
  ina226.readAndClearFlags();
  shuntVoltage_mV = ina226.getShuntVoltage_mV();
  Serial.println(shuntVoltage_mV);
  if (!ina226.overflow) {
    busVoltage_V = ina226.getBusVoltage_V();
    amperage_28V_Line = ina226.getCurrent_mA() / 100;
    voltage_28V_Line  = (busVoltage_V + (shuntVoltage_mV / 1000)) * 10;
  }
  // Assigning  values for the other variables
  temperature_other = 999;
  voltage_5V_Line = 888;
  amperage_5V_Line = 777;
  voltage_12V_Line = 666;
  amperage_12V_Line = 555;
  other_parameter_1 = 444;
  other_parameter_2 = 333;
  other_parameter_3 = 222;
  PTT_Relay_status = 111;

  // Contructing packet with delimiters
  packet = "X|" + String(temperature_ambient) + "|";
  packet = packet + String(temperature_heatsink) + "|";
  packet = packet + String(voltage_28V_Line) + "|";
  packet = packet + String(amperage_28V_Line) + "|";
  packet = packet + String(temperature_other) + "|";
  packet = packet + String(voltage_5V_Line) + "|";
  packet = packet + String(amperage_5V_Line) + "|";
  packet = packet + String(voltage_12V_Line) + "|";
  packet = packet + String(amperage_12V_Line) + "|";
  packet = packet + String(other_parameter_1) + "|";
  packet = packet + String(other_parameter_2) + "|";
  packet = packet + String(other_parameter_3) + "|";
  packet = packet + String(PTT_Relay_status) + "|";
  packet = packet + "X\n";

  Serial.print("Sending Packet "); Serial.println(packet);
  HC12_Serial.print(packet);
  delay(500);  // packet intervals in ms, will be shortened at a later stage
}


//############ FUNCTIONS ########################################################################################

// function to return temperature values
float get_temp_from_Sensor(DeviceAddress deviceAddress)
{
  float tempC = Dallas_temperature_sensors.getTempC(deviceAddress);

  if (tempC == DEVICE_DISCONNECTED_C)
  {
    Serial.println("Error: Could not read temperature data");
    return 0;
  }
  return tempC;
}





Output in Python