home autimation - temperature sensors 18b20

Hello,
few weeks ago I started working on control board for smart home control, especialy for heating. During proposal of PCB i decided to use arduino Nano and ENC28J60 ethernet (what was not good choice). During the first test when i turned on few 18b20 and turned on few relays everything goes right, but when i increase number of temperature sensors (around 6) then i had problem with GET method. String which should contain data about temperatures wass empty. All sensors have own data pin and i used multibus for get values and in “for each” a preparing final get string. I thing that i should not used string for store all these data, but maybe char. Memory of arduino is around 84%, this shouldn be problem i think. I will be glad for every help, thx :slight_smile:

for (int i = 0; i < oneWireCount; i++) {
    sensor[i].requestTemperatures();
    postData = postData + "Zarizeni_ID_" + i + "=" + i + "&Atribut_" + i + "=1 & Hodnota_" + i + "=" + sensor[i].getTempCByIndex(0);
  }

control board

full code

ude <DallasTemperature.h>
//bojler vrsek, bojler spodek, aku nadrz,obyvak termostat,
OneWire ds18x20[] = { 7, 8, 6, 5, 9 };
const int oneWireCount = sizeof(ds18x20) / sizeof(OneWire);
DallasTemperature sensor[oneWireCount];

int  Getinterval = 3000; 
unsigned long GetMethodTime; 
String postData;
String tempData;
//PCF
//------------------------------------------------------
#include "PCF8574.h"
#include <Wire.h>
PCF8574 pcf(0x20);
PCF8574 pcf2(0x21);
PCF8574 pcf3(0x22);
PCF8574 pcf4(0x23);
int DeviceString[10];
int DeviceIncrement;
int StatusString[10];
uint8_t ValveString[10];
//------------------------------------------------------
//topeni kohouty
//RadiatoryON,AkuNadryON,AkuNadryON,KuchyneON
//RadiatoryOFF,AkuNadryOFF,KoupelnaON,KuchyneOFF
const byte EndSwitchON[4] = {0, 2, 4, 6};
const byte EndSwitchOFF[4] = {1, 3, 5, 7};

void setup() {
  Serial.begin(9600);
  //ethernet
  Ethernet.begin(mac, ip, dns2, gateway, subnet);
  Serial.println(Ethernet.localIP());
  Serial.println(Ethernet.subnetMask());
  Serial.println(Ethernet.gatewayIP());
  Serial.println(Ethernet.dnsServerIP());

//dallas teplomery
  DeviceAddress deviceAddress;
  for (int i = 0; i < oneWireCount; i++) {
    sensor[i].setOneWire(&ds18x20[i]);
    sensor[i].begin();
    if (sensor[i].getAddress(deviceAddress, 0)) sensor[i].setResolution(deviceAddress, 12);
  }

  //pcf
  pcf.begin();
  pcf2.begin();
  pcf3.begin();
  pcf4.begin();
}

void loop() {
  if (millis() > GetMethodTime + Getinterval) {
    getTemps();
    sendGET();
    GetMethodTime = millis();
  }
  //Valve();
}

void getTemps() {
  postData = "";
  for (int i = 0; i < oneWireCount; i++) {
    sensor[i].requestTemperatures();
    postData = postData + "Zarizeni_ID_" + i + "=" + i + "&Atribut_" + i + "=1 & Hodnota_" + i + "=" + sensor[i].getTempCByIndex(0);
  }
  Serial.println(postData);
}

void Valve() {
  for (int i = 0; i < 10; i++) {
    if (ValveString[i] != 0) {
      switch (StatusString[i]) {
        case 0:
          if (pcf4.readButton(EndSwitchOFF[ValveString[i - 1]]) == true ) {
            pcf.write(ValveString[i],  1);
          }
          else
          {
            pcf.write(ValveString[i],  0);
          }
          break;
        case 1:
          if (pcf4.readButton(EndSwitchON[ValveString[i - 1] ]) == true ) {
            pcf.write(ValveString[i],  1);
          }
          else
          {
            pcf.write(ValveString[i],  0);
          }
          break;
      }
    }
  }
}

void sendGET() {
  if (client.connect(server, 80)) {  //starts client connection, checks for connection
    Serial.println(F("connected"));
    client.print(F("GET adresa));
    client.println(F(" HTTP / 1.1")); //download text
    client.println(F("Content - Type: application / x - www - form - urlencoded"));
    client.println(F("Host: server"));
    client.println(F("Connection: close"));  //close 1.1 persistent connection
    client.print(F("Content - Length: "));
    client.println(postData.length());
    client.println();
    client.print(postData);
    delay(10);

  }
  else {
    Serial.println(F("connection failed"));
    return;
  }
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      //Serial.println(F(" >>> Client Timeout !"));
      client.stop();
      return;
    }
  }
  DeviceIncrement = 0;
  while (client.connected() && !client.available()) delay(50); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char m = client.read(); //gets byte from ethernet buffer
    // d - device
    // v - valve device
    // s - status
    if (m == '#') {
      char n =  client.read();
      if (n == 'd') {
        DeviceString[DeviceIncrement] = client.readStringUntil('*').toInt();
        DeviceIncrement = DeviceIncrement + 1;
      }
      //      if (n == 'v') {
      //        ValveString[DeviceIncrement - 1] = client.readStringUntil('*').toInt();
      //        DeviceIncrement = DeviceIncrement + 1;
      //      }
      if (n == 's') {
        StatusString[DeviceIncrement - 1] = client.readStringUntil('*').toInt();
        if (StatusString[DeviceIncrement - 1] == 0) {
          if (DeviceString[DeviceIncrement - 1] <= 7) {
            pcf.write(DeviceString[DeviceIncrement - 1],  1);
          }
          else
          {
            pcf2.write(DeviceString[DeviceIncrement - 8],  1);
          }
        }
        else {
          if (DeviceString[DeviceIncrement - 1] <= 7) {
            pcf.write(DeviceString[DeviceIncrement - 1],  0);
          }
          else {
            pcf2.write(DeviceString[DeviceIncrement - 8],  0);
          }
        }
      }
    }
  }
  client.stop();
}

Zdravím,
před nedávnem jsem se spustil do vyroby ridici desky pro ovladani domu, predevsim bojleru a topeni (pro zacatek). Pri navrhu desky jsem se rozhodl pouzi arduino nano a ENC28J60 ethernet (coz nyni vim ze nebyla dobra volba pro usetreni mista na pcb). Pri zapojeni prvnich cidel a rele vse fungovalo bez problemu (prozatim teplotni cidla ds18b20, ktera jsou pripojena kazde zvlast na vlastni port a vytvarim z nich multibus). Bohuzel jakmile jsem prekrocil 5te teplotni cidlo tak retezeni cidel nejak prestalo fungovat, i kdyz vyuziti pameti se nijak nezmenilo. Pri vyprintovani vysledku na serial vzdy dostanu pouze prazdnou hodnotu. Vytvarim vetsi retezec pro GET metodu, atributy jsou pripraveny pro budouci cidla. Proto bych Vas chtel pozadat o radu v cem muze byt problem. Jestli vyuzit jiny datovy typ nez string?

Memory of arduino is around 84%, this shouldn be problem i think.

I rather suspect that it is. You’re left with ~330 bytes to handle the stack and your Strings. The Strings really need to go, but even then, you may need to find a way to shave off some more memory.

I can see a couple of minor quick wins: the parameters in your GET string such as Zarizeni_ID_ are nicely human readable but unnecessarily long, you can save a tiny bit by making them shorter and more cryptic.

Don’t use int where byte will do: you have some for loops that do this and I suspect that some of your arrays that are int need only be byte too.