Send multiple DS18B20 values by UDP

Good evening all,
Started recently with the Arduino IDE.
I’m working on a project where the address and temperature value of multiple DS18B20 sensors is transmitted via UDP to a Gira Homeserver (HS3).
Getting very close to finishing the sketch with only 1 real issue left…

First issue:
Whenever I use the Ethernet.h library (only) the first compile of the sketch produces a Warning which includes the text: “warning: result of ‘(256 << 8)’ requires 18 bits to represent, but ‘int’ only has 16 bits”.
Even with the Ethernet examples this happens.
A bug in the library or a wrong setting?

Second issue:
I’m trying for a couple of days now to send the 8-byte address of the sensor with it’s temperature via UDP.
The resulting string should look like: 28B29E1B000000CE=19.31
Somehow I can’t convert the address/temperature into a string.
Sending a fixed text over UDP works fine.
Help is appreciated…

#include <OneWire.h>                                                      // One-wire devices
#include <DallasTemperature.h>                                            // DS18B20
#include <SPI.h>
#include <Ethernet.h>

// DS18B20
OneWire oneWire(2);                                                       // Setup a oneWire instance to communicate with any OneWire device on pin 2
DallasTemperature temperatureSensors(&oneWire);                           // Pass oneWire reference to DallasTemperature library
DeviceAddress sensorAddress[30];                                          // variable to hold sensor addresses
float sensorNewTempC[30];                                                 // variable to hold sensor temperature
float sensorOldTempC[30];                                                 // variable to hold sensor temperature
int sensorTimeCounter[30];                                                // variable to hold seconds without temp being sent by UDP
int sensorCount = 0;                                                      // variable to hold number of sensors
int sensorindex;                                                          // variable to hold sensor pointer
int index;

// Ethernet
byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};                        // Enter a MAC address for your controller below.
byte macBuffer[6];                                                        // create a buffer to hold the MAC address
IPAddress ip_receiver(192, 168, 1, 104);                                  // 104-laptop FOR TESTING!!!!!!!!!!!
unsigned int receiverport = 8888;                                         // Port to send packets to
EthernetUDP Udp;                                                          // An EthernetUDP instance to let us send and receive packets over UDP
  


void setup(void)
{
// Serial communication (USB)
  Serial.begin(115200);
  while (!Serial) {;}                                                     // wait for serial port to connect. Needed for native USB port only
  Serial.println("Serial port active");
// Ethernet  
  Serial.println("Working on the ethernet part now");
  Ethernet.begin(mac);
  Udp.begin(receiverport);
 // Ethernet connection:
  Serial.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
      Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    } else if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
    }
    while (true) {delay(1);}                                              // no point in carrying on, so do nothing forevermore:
  }
  Serial.print("My IP address: ");                                        // print your local IP address:
  Serial.println(Ethernet.localIP());
  Ethernet.MACAddress(macBuffer);                                         // Put MAC address in macBuffer
  Serial.print("The MAC address is: ");
  for (byte octet = 0; octet < 6; octet++)
  {
    if (macBuffer[octet]<16) {Serial.print('0');}
    Serial.print(macBuffer[octet], HEX);
    if (octet < 5) {Serial.print('-');}
  }
  Serial.println();
  

// DS18B20
  temperatureSensors.begin();                                             // Start up the library
  temperatureSensors.requestTemperatures();                               // Send command to all the sensors for temperature conversion
  getSensorsOnBus();


Serial.println("Program starting now.");
Serial.println();
}



//===============================================================================================================================================
void loop(void)
{
  temperatureSensors.requestTemperatures();                               // Send command to all the sensors for temperature conversion
  for (sensorindex = 0;  sensorindex < sensorCount;  sensorindex++)
  {
    if (sensorTimeCounter[sensorindex]==20)                               // 20 loops passed without sending this sensor's temperature
    {
      sensorTimeCounter[sensorindex]=0;
 //     sendTempUDP();                                                    // Send temperature at least once evey 20 conversions
    }
    else if (sensorNewTempC[sensorindex]!=sensorOldTempC[sensorindex])
    {
      sensorTimeCounter[sensorindex]=0;
//      sendTempUDP();                                                    // Send temperature when changed
    }
    else
    {
      sensorTimeCounter[sensorindex]++;                                   // Increase the sensorTimeCounter for this sensor
    }
  }
  sendTempSerial();                                                       // Print sensor data for testing
  sendTempUDP();
  while (oneWire.read() == 0) {  }                                        // wait for conversion end
  for (sensorindex = 0;  sensorindex < sensorCount;  sensorindex++)
  {
    sensorNewTempC[sensorindex] = temperatureSensors.getTempCByIndex(sensorindex);  //Read out all temperatures
  }
  Serial.println();
}
//===============================================================================================================================================



void getSensorsOnBus()                                                    // Find sensors on the bus
{ 
  Serial.print("Locating devices...");
  Serial.print("Found ");
  sensorCount = temperatureSensors.getDeviceCount();
  Serial.print(sensorCount, DEC);
  Serial.println(" device(s).");
  while (sensorCount==0)                                                  // Loop here when no sensors are found (subject to change)
  {
    delay(1);
  }
  for (index = 0;  index < sensorCount;  index++)                         // Fill up the sensorAddress array with addresses found
  {
    temperatureSensors.getAddress(sensorAddress[index], index);           // Why twice index??
    temperatureSensors.setResolution(sensorAddress[index], 12);           // Default is 12 bits (0,0625)
    printAddress(sensorAddress[index]);
    Serial.print("   ");
    sensorNewTempC[index]=temperatureSensors.getTempCByIndex(index);
    sensorOldTempC[index]=sensorNewTempC[index];
    Serial.println(sensorNewTempC[index]);
  }
  Serial.println("");
}


void printAddress(DeviceAddress sensorAddress)                            // function to print all sensor addresses
{
  for (byte i = 0; i < 8; i++)
  {
    if (sensorAddress[i] < 16) Serial.print("0");
    Serial.print(sensorAddress[i], HEX);
  }
  Serial.print("  ");
}


void sendTempUDP()
{
  sensorTimeCounter[sensorindex]=0;                                        // Reset sensorTimeCounter
  Udp.beginPacket(ip_receiver, receiverport);
  String tempstring = sensorAddress[sensorindex];                          // Invalid conversion / Incompatible assgnment.........
  Udp.write(tempstring);                                                   // no matching function for call.....
  Udp.write("DS18B20 sensor  ");                                           // Lest's start with some text first...That works!
  for (byte i = 0; i < 8; i++)
    {
      if (tempstring[i]<16) {Udp.print('0');}
      Udp.print(tempstring[i], HEX);
    }
  Udp.endPacket();
}


void sendTempSerial()
{
  sensorTimeCounter[sensorindex]=0;                                        // Reset sensorTimeCounter
  for (sensorindex = 0;  sensorindex<sensorCount; sensorindex++)
  {
    Serial.print(sensorindex);
    Serial.print(" ");
    Serial.print(sensorNewTempC[sensorindex]);
    Serial.print(" (");
    if (sensorTimeCounter[sensorindex]<10) {Serial.print(" ");}            // For allignment
    Serial.print(sensorTimeCounter[sensorindex]);
    Serial.print(")   ");
    sensorOldTempC[sensorindex]=sensorNewTempC[sensorindex];
  }
}

747driver:
The resulting string should look like: 28B29E1B000000CE=19.31

A bug in the library or a wrong setting?

Probably not the former, quite likely not the latter, more likely user misunderstanding.
You seem to have a problem nobody else has, and you need to know why that might be. So, is there a purpose in sending a string like that? Is that demanded by the homeserver?
There will be examples on the library that show the sort of output that everybody else uses. Another example is here

Thanks Nick.
I’ve seen that 1-wire tutorial before.
In fact, I think I’ve seen them all by now.

I’m using Arduino 1.8.10
When I open File - Examples - Ethernet - DhcpAddressPrinter and compile the sketch I get the attached message.
Looks like I’m getting the same message with all Ethernet examples.
It’s only the first time when I compile them after opening the file.
Could you give it a try please?

Sorry, forgot to answer the other question.
I programmed the Homeserver in such a way that it listens to a specific port for UDP messages.
The Homeserver is primarily meant to be used with a KNX bus system but can do this as well.
It expects a 1-wire address followed by a "=" followed by a temperature.
Upon receiving such a packet the corresponding variable in the Homeserver is updated.

The sensors are used to measure the temperature of our heating system.
All the floor heating loops have a sensor for in/out water temperature.
In the middle of every loop (in the floor) there is a sensor as well.

The Arduino doing the job right now is programmed with BASCOM-8051 and I wrote the program for 95% in 8051 assembly language.
As I'm using an OSX laptop and don't want to open VMware Fusion every time I want to work on this project I decided to start using the Arduino IDE.

747driver:
Could you give it a try please?

OK, it looks like you have justified sending that sort of string, but I'm afraid there is nothing I can try, as I have no idea of what you are doing, and I don't know what UDP is. My only experience with Ethernet is when using IoT, in which event I just did what the service provider told me to do, after getting the values in the Hacktronics manner.
The address printer example compiles exactly as it is supposed to.

Could just try by opening the DhcpAddressPrinter example and compile it once?

@747driver

Thread LOCKED to dissapear below the waves and sink without a trace.

Pick your main languaGE and STICK TO THAT.
Cross posting will simply annoy people and get you kicked out.

Please READ THIS before doing yourself any more harm.

Bob.