Device Core and particle.function

Hello
I have some Core devices and would like to use them for small applications. Unfortunately if I use device Core this line does not accept it (setPoint = arg.toFloat ():wink: in a particle.function. The Cores all have firmware 1.4.4. Is there a workaround so that I can enter the temperature in my case either from the console or from the mobile app?
Thanks Valentino

What is the error message and what is the definition of setPoint?
It’s probably best to post your entire Particle.function() callback to see what’s going on.

BTW, when posting “normal” text you would not use the preformatted text block feature (```). That’s typically used for code blocks.

Hello @ScruffR
I’m using part of the code corrected by you, it’s simple, during the Christmas holidays I wanted to make panettone and I was missing a leavening cell (for bread, panettone, etc.) with the respective adjustment of temperature. So I took the code and made it simple for my knowledge. The PID code that you corrected in December I am not able to make it work, for now step by step I want to try again.
When I compile the code it tells me Error: Could not compile. Please review your code.
The code is attached.
Thanks Valentino

#include <math.h>
#include "Particle.h"

#include <OneWire.h>
#include <DS18.h>

//*** Dati Umidita***
double sensorUm = 0.0;
float voltUM=0.0;
double UmidTRH;
double UmidV;
float HHconstant=0.1515;      // from HIH5030 data sheet


//*** Sensori Temp
DS18 pinTempSensor(D3); // sensore 1
float TV1;
double temp;
int pinRelay = D0;
bool stato = true;

double setPoint;
//String Ora;

void setup() {
    Particle.function("newSetPoint", newSetPoint);
    Particle.variable("Temp", temp);
    Particle.variable("Umi", UmidV);
    Serial.begin(9600);
    pinMode(pinRelay, OUTPUT);
    setPoint = 22;
}
  
void loop(){
  if (pinTempSensor.read()) {
     TV1 = pinTempSensor.celsius();
  }
  temp = TV1;
  if (TV1 < setPoint) { 
    digitalWrite(pinRelay, HIGH);
    stato = true;
  }
  else {
    digitalWrite(pinRelay, LOW);
    stato = false;
  }
  //***Calcolo Dati Umidita***
  sensorUm = analogRead(A0);
  UmidV = ((sensorUm / 4095) - 0.1515) / 0.00636;
  UmidTRH = (UmidV) / (1.0546 - 0.00216 * TV1);
  //*****
  //Serial.print("Ora:"); Serial.print(Ora);
  Serial.print("Stato:"); Serial.print(stato); Serial.print(" ");
  Serial.print("temp:"); Serial.print(TV1); Serial.print(" ");
  Serial.print("Set:"); Serial.print(" "); Serial.print(setPoint); Serial.print(" ");
  Serial.print("Umi:"); Serial.println(UmidV, 2);
  //Pubblicare i valori
  /*char dataImp[21];
  snprintf(dataImp, sizeof(dataImp), "T:%.1f,S:%.1f,U:%.1f", TV1, setPoint, UmidV);
  Particle.publish("Valori", dataImp, PRIVATE);*/
  delay(1000);
}

int newSetPoint(String arg) {
  setPoint = arg.toFloat();
  return setPoint;
}

In that case you should hit the red SHOW RAW button near the error message to get a more verbose description of the underlying issue.
You can post that output here too.

Just some coding tips too

  if (TV1 < setPoint) { 
    digitalWrite(pinRelay, HIGH);
    stato = true;
  }
  else {
    digitalWrite(pinRelay, LOW);
    stato = false;
  }

can be written shorter as

  stato = (TV1 < setPoint);
  digitalWrite(pinRelay, stato);

or even as one-liner

  digitalWrite(pinRelay, stato = (TV1 < setPoint));

althouth the two-liner is easier to read :wink:

I’m also not sure, why you still opt for multiple Serial.print() statements when you already have a perfectly fine snprintf() there

  char dataImp[128];
  snprintf(dataImp, sizeof(dataImp), "T:%.1f,S:%.1f,U:%.1f", TV1, setPoint, UmidV);
  Serial.println(dataImp);

or to copy the Serial.print() output

  char dataImp[128];
  snprintf(dataImp, sizeof(dataImp), "Stato:%d temp:%.1f Set: %.1f Umi:%.2f", stato, TV1, setPoint, UmidV);
  Serial.println(dataImp);

@Tino52, There are a couple of things you may want to look at. First arg.toFloat() returns a type float but setPoint is a type double. So you could cast the return from arg.toFloat() as a double using:

setPoint = (double)arg.toFloat();

Second, the newSetPoint() callback function needs to return an int but you return setPoint which is a double. Again, you could cast setPoint as an int to only return the integer portion of the value or simply return an integer value, say 1, to indicate a “complete” response. So:

return (int)setPoint;

One thing you may want to consider is range-checking the setPoint value to make sure it is within an acceptable range. If it isn’t you, the function could return a zero.

Hello @peekay123 and @ScruffR
Thanks for your answers, @peekay123 I made the suggested changes but it always responds the same (Could not compile please …), I don’t know if I have expressed myself well with Argon and Photon the code does not work if I use Core device. And if I do a REM (//) on line

/* int newSetPoint (String arg) {
   // setPoint = arg.toFloat ();
   setPoint = (double) arg.toFloat ();
   // return setPoint;
   return (int) setPoint;}*/

gives me no error.
I attach the result of the error (Show raw).
Thank you and good day

Processing  02cellalievipt100.ino
Checking library OneWire...
Checking library DS18B20...
Installing library OneWire 2.0.4 to lib/OneWire ...
Installing library DS18B20 0.1.14 to lib/DS18B20 ...
Library OneWire 2.0.4 installed.
Library DS18B20 0.1.14 installed.
make -C ../newlib_nano 
make[1]: Entering directory '/firmware/newlib_nano'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/firmware/newlib_nano'
make -C ../user 
make[1]: Entering directory '/firmware/user'
Building cpp file: src/02cellalievipt100.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p ../build/target/user/platform-0-ltosrc/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F10X_MD -DPLATFORM_THREADING=0 -DPLATFORM_ID=0 -DPLATFORM_NAME=core -DUSBD_VID_SPARK=0x1D50 -DUSBD_PID_DFU=0x607F -DUSBD_PID_CDC=0x607D -DSPARK_PLATFORM -DFLASHEE_EEPROM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -flto -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=0 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=1.4.4 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../third_party/miniz/miniz -I../services/inc -I../third_party/nanopb/nanopb -I../communication/inc -I../hal/inc -I../hal/shared -I../hal/src/core -I../hal/src/stm32 -I../platform/shared/inc -I../platform/MCU/STM32F1xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F1xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F1xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F1xx/CMSIS/Include -I../platform/MCU/STM32F1xx/CMSIS/Device/ST/Include -I../platform/NET/CC3000/CC3000_Host_Driver -I../dynalib/inc -Isrc -I./libraries -Ilib/DS18B20/src -Ilib/OneWire/src -I. -MD -MP -MF ../build/target/user/platform-0-ltosrc/02cellalievipt100.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DSPARK_PLATFORM_NET=CC3000 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc  -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DMODULE_VERSION=1406 -DMODULE_FUNCTION=3 -DMODULE_DEPENDENCY=0,0,0 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY="\"app\""  -fno-exceptions -fno-rtti -fcheck-new -std=gnu++14 -c -o ../build/target/user/platform-0-ltosrc/02cellalievipt100.o src/02cellalievipt100.cpp

Building cpp file: lib/DS18B20/src/DS18B20.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p ../build/target/user/platform-0-ltoDS18B20/src/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F10X_MD -DPLATFORM_THREADING=0 -DPLATFORM_ID=0 -DPLATFORM_NAME=core -DUSBD_VID_SPARK=0x1D50 -DUSBD_PID_DFU=0x607F -DUSBD_PID_CDC=0x607D -DSPARK_PLATFORM -DFLASHEE_EEPROM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -flto -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=0 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=1.4.4 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../third_party/miniz/miniz -I../services/inc -I../third_party/nanopb/nanopb -I../communication/inc -I../hal/inc -I../hal/shared -I../hal/src/core -I../hal/src/stm32 -I../platform/shared/inc -I../platform/MCU/STM32F1xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F1xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F1xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F1xx/CMSIS/Include -I../platform/MCU/STM32F1xx/CMSIS/Device/ST/Include -I../platform/NET/CC3000/CC3000_Host_Driver -I../dynalib/inc -Isrc -I./libraries -Ilib/DS18B20/src -Ilib/OneWire/src -I. -MD -MP -MF ../build/target/user/platform-0-ltoDS18B20/src/DS18B20.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DSPARK_PLATFORM_NET=CC3000 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc  -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DMODULE_VERSION=1406 -DMODULE_FUNCTION=3 -DMODULE_DEPENDENCY=0,0,0 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY="\"app\""  -fno-exceptions -fno-rtti -fcheck-new -std=gnu++14 -c -o ../build/target/user/platform-0-ltoDS18B20/src/DS18B20.o lib/DS18B20/src/DS18B20.cpp

Building cpp file: lib/OneWire/src/DS18.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p ../build/target/user/platform-0-ltoOneWire/src/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F10X_MD -DPLATFORM_THREADING=0 -DPLATFORM_ID=0 -DPLATFORM_NAME=core -DUSBD_VID_SPARK=0x1D50 -DUSBD_PID_DFU=0x607F -DUSBD_PID_CDC=0x607D -DSPARK_PLATFORM -DFLASHEE_EEPROM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -flto -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=0 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=1.4.4 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../third_party/miniz/miniz -I../services/inc -I../third_party/nanopb/nanopb -I../communication/inc -I../hal/inc -I../hal/shared -I../hal/src/core -I../hal/src/stm32 -I../platform/shared/inc -I../platform/MCU/STM32F1xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F1xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F1xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F1xx/CMSIS/Include -I../platform/MCU/STM32F1xx/CMSIS/Device/ST/Include -I../platform/NET/CC3000/CC3000_Host_Driver -I../dynalib/inc -Isrc -I./libraries -Ilib/DS18B20/src -Ilib/OneWire/src -I. -MD -MP -MF ../build/target/user/platform-0-ltoOneWire/src/DS18.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DSPARK_PLATFORM_NET=CC3000 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc  -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DMODULE_VERSION=1406 -DMODULE_FUNCTION=3 -DMODULE_DEPENDENCY=0,0,0 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY="\"app\""  -fno-exceptions -fno-rtti -fcheck-new -std=gnu++14 -c -o ../build/target/user/platform-0-ltoOneWire/src/DS18.o lib/OneWire/src/DS18.cpp

Building cpp file: lib/OneWire/src/OneWire.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p ../build/target/user/platform-0-ltoOneWire/src/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F10X_MD -DPLATFORM_THREADING=0 -DPLATFORM_ID=0 -DPLATFORM_NAME=core -DUSBD_VID_SPARK=0x1D50 -DUSBD_PID_DFU=0x607F -DUSBD_PID_CDC=0x607D -DSPARK_PLATFORM -DFLASHEE_EEPROM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -flto -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=0 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=1.4.4 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../third_party/miniz/miniz -I../services/inc -I../third_party/nanopb/nanopb -I../communication/inc -I../hal/inc -I../hal/shared -I../hal/src/core -I../hal/src/stm32 -I../platform/shared/inc -I../platform/MCU/STM32F1xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F1xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F1xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F1xx/CMSIS/Include -I../platform/MCU/STM32F1xx/CMSIS/Device/ST/Include -I../platform/NET/CC3000/CC3000_Host_Driver -I../dynalib/inc -Isrc -I./libraries -Ilib/DS18B20/src -Ilib/OneWire/src -I. -MD -MP -MF ../build/target/user/platform-0-ltoOneWire/src/OneWire.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DSPARK_PLATFORM_NET=CC3000 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc  -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DMODULE_VERSION=1406 -DMODULE_FUNCTION=3 -DMODULE_DEPENDENCY=0,0,0 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY="\"app\""  -fno-exceptions -fno-rtti -fcheck-new -std=gnu++14 -c -o ../build/target/user/platform-0-ltoOneWire/src/OneWire.o lib/OneWire/src/OneWire.cpp

Building target: ../build/target/user/platform-0-ltolibuser.a
Invoking: ARM GCC Archiver
mkdir -p ../build/target/user/platform-0-lto
arm-none-eabi-gcc-ar -cr ../build/target/user/platform-0-ltolibuser.a ../build/target/user/platform-0-ltosrc/02cellalievipt100.o ../build/target/user/platform-0-ltoDS18B20/src/DS18B20.o ../build/target/user/platform-0-ltoOneWire/src/DS18.o ../build/target/user/platform-0-ltoOneWire/src/OneWire.o

make[1]: Leaving directory '/firmware/user'
make -C ../wiring 
make[1]: Entering directory '/firmware/wiring'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/firmware/wiring'
make -C ../hal 
make[1]: Entering directory '/firmware/hal'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/firmware/hal'
make -C ../system 
make[1]: Entering directory '/firmware/system'
make -C ../third_party/miniz 
make[2]: Entering directory '/firmware/third_party/miniz'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/firmware/third_party/miniz'
make[1]: Leaving directory '/firmware/system'
make -C ../services 
make[1]: Entering directory '/firmware/services'
make -C ../third_party/nanopb 
make[2]: Entering directory '/firmware/third_party/nanopb'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/firmware/third_party/nanopb'
make[1]: Leaving directory '/firmware/services'
make -C ../communication 
make[1]: Entering directory '/firmware/communication'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/firmware/communication'
make -C ../platform 
make[1]: Entering directory '/firmware/platform'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/firmware/platform'
make -C ../wiring_globals 
make[1]: Entering directory '/firmware/wiring_globals'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/firmware/wiring_globals'
make -C ../crypto 
make[1]: Entering directory '/firmware/crypto'
make -C ../third_party/mbedtls 
make[2]: Entering directory '/firmware/third_party/mbedtls'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/firmware/third_party/mbedtls'
make[1]: Leaving directory '/firmware/crypto'
Building c file: src/module_info.c
Invoking: ARM GCC C Compiler
mkdir -p target/obj/./src/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F10X_MD -DPLATFORM_THREADING=0 -DPLATFORM_ID=0 -DPLATFORM_NAME=core -DUSBD_VID_SPARK=0x1D50 -DUSBD_PID_DFU=0x607F -DUSBD_PID_CDC=0x607D -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -flto -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=0 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DMBEDTLS_CONFIG_FILE="<mbedtls_config.h>" -DSYSTEM_VERSION_STRING=1.4.4 -DRELEASE_BUILD -Werror -I../user/inc -I../wiring/inc -I../hal/inc -I../hal/shared -I../hal/src/core -I../hal/src/stm32 -I../system/inc -I../third_party/miniz/miniz -I../services/inc -I../third_party/nanopb/nanopb -I../communication/inc -I../platform/shared/inc -I../platform/MCU/STM32F1xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F1xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F1xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F1xx/CMSIS/Include -I../platform/MCU/STM32F1xx/CMSIS/Device/ST/Include -I../platform/NET/CC3000/CC3000_Host_Driver -I../crypto/inc -I../third_party/mbedtls/mbedtls/include -I../dynalib/inc -I. -MD -MP -MF target/obj/./src/module_info.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DMODULE_VERSION=1406 -DMODULE_FUNCTION=3 -DMODULE_DEPENDENCY=0,0,0 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE  -std=gnu11 -Wno-pointer-sign -c -o target/obj/./src/module_info.o src/module_info.c

Building file: ../build/arm/startup/startup_stm32f10x_md.S
Invoking: ARM GCC Assembler
mkdir -p target/obj/startup/
arm-none-eabi-gcc -g3 -gdwarf-2 -mcpu=cortex-m3 -mthumb -I../build/arm/startup -Wa,--defsym -Wa,SPARK_INIT_STARTUP=1 -x assembler-with-cpp -fmessage-length=0 -c -o target/obj/startup/startup_stm32f10x_md.o ../build/arm/startup/startup_stm32f10x_md.S

Building target: target/workspace.elf
Invoking: ARM GCC C++ Linker
mkdir -p target/
arm-none-eabi-g++ -DSTM32_DEVICE -DSTM32F10X_MD -DPLATFORM_THREADING=0 -DPLATFORM_ID=0 -DPLATFORM_NAME=core -DUSBD_VID_SPARK=0x1D50 -DUSBD_PID_DFU=0x607F -DUSBD_PID_CDC=0x607D -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -flto -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=0 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DMBEDTLS_CONFIG_FILE="<mbedtls_config.h>" -DSYSTEM_VERSION_STRING=1.4.4 -DRELEASE_BUILD -Werror -I../user/inc -I../wiring/inc -I../hal/inc -I../hal/shared -I../hal/src/core -I../hal/src/stm32 -I../system/inc -I../third_party/miniz/miniz -I../services/inc -I../third_party/nanopb/nanopb -I../communication/inc -I../platform/shared/inc -I../platform/MCU/STM32F1xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F1xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F1xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F1xx/CMSIS/Include -I../platform/MCU/STM32F1xx/CMSIS/Device/ST/Include -I../platform/NET/CC3000/CC3000_Host_Driver -I../crypto/inc -I../third_party/mbedtls/mbedtls/include -I../dynalib/inc -I. -MD -MP -MF target/workspace.elf.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DMODULE_VERSION=1406 -DMODULE_FUNCTION=3 -DMODULE_DEPENDENCY=0,0,0 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE target/obj/./src/module_info.o  target/obj/startup/startup_stm32f10x_md.o --output target/workspace.elf -nostartfiles -Xlinker --gc-sections -flto -Os -fuse-linker-plugin -Tlinker_stm32f10x_md_dfu.ld -L../build/arm/linker --specs=nano.specs -lc -lnosys -u _printf_float -Wl,-Map,target/workspace.map  -L../build/target/user/platform-0-lto -L../build/target/wiring/platform-0-lto/ -L../build/target/system/platform-0-lto/ -L../build/target/services/platform-0-lto/ -L../build/target/communication/platform-0-lto-prod-0/ -L../build/target/hal/platform-0-lto/ -L../build/target/platform/platform-0-lto/ -L../build/target/wiring_globals/platform-0-lto/ -L../build/target/crypto/platform-0-lto/ -L../build/target/newlib_nano/platform-0-lto -L../build/target/miniz/platform-0-lto -L../build/target/nanopb/platform-0-lto -L../build/target/mbedtls/platform-0-lto -L../build/arm/linker -Wl,--whole-archive -lnewlib_nano -luser -lwiring -lhal -lsystem -lservices -lcommunication -lplatform -lwiring_globals -lcrypto -lminiz -lnanopb -lmbedtls -Wl,--no-whole-archive 
/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/5.3.1/../../../../arm-none-eabi/bin/ld: target/workspace.elf section `.text' will not fit in region `APP_FLASH'
/usr/local/gcc-arm-embedded/bin/../lib/gcc/arm-none-eabi/5.3.1/../../../../arm-none-eabi/bin/ld: region `APP_FLASH' overflowed by 3800 bytes
collect2: error: ld returned 1 exit status
../build/module.mk:232: recipe for target 'target/workspace.elf' failed
make: *** [target/workspace.elf] Error 1

The last few lines of your error report tell the story


The Core has considerably less flash (and RAM) than the other two (Photon and Argon), hence the resulting binary will not fit onto that board.

So it’s not what the function does but rather how much code you write.
With 1.4.4. a lot of the available flash will already be used for the device OS and very little remains for your actual “business logic”.
With the Core and a simple program like yours you may want to stick to 1.0.0 or even 0.7.0

To reduce your code size, you can try

  • avoiding double and use float instead.
  • streamline your code just like I suggested above
  • shorten your string literals.
  • drop Serial.begin() as it’s already called by the system internally
  • avoid redundancy (e.g. temp and TV1 are virtually the same thing, so one should go)
1 Like

Hi @ScruffR
Thanks for the help of the suggestions, see if I can streamline the code.
Have a nice weekend
Valentino

1 Like

Hello @ScruffR
Hello
today I streamlined the code but without great results. Do you by any chance have a suggestion to avoid using the particle.function but to be able to set the temperature from the console or from the apps?
I enclose the test results.
Happy Sunday and thank you for your precious help.
With Particle.function

text	data	bss	dec	hex
18056	480	1460	19996	4
In a nutshell:
Flash used	18536 bytes
RAM used	1940 bytes

Without Particle.function

text	data	bss	dec	hex
9308	112	1460	10880	2
In a nutshell:
Flash used	9420 bytes
RAM used	1572 bytes

Have you changed the target Device OS version as suggested above?


This code fits (only just) into the Core when building against no higher than 1.0.1

#include <DS18.h>

const int	pinRelay	= D0;
const int   pinSensor	= D3;
const int	pinUmid		= A0;
const float vOffset		= 620.3935; // == 0.1515  * 4095
const float vFactor		=  26.0442; // == 0.00636 * 4095 
const float tBase       =   1.0546;
const float tFactor     =   0.00216;

float       setPoint    =  22.0;
char		env[64];

DS18 sensor(pinSensor);

void setup() {
  Particle.function("set", setTarget);
  //Particle.variable("env", env);
  pinMode(pinRelay, OUTPUT);
}
  
void loop() {
//static uint32_t ms    = 0;
//if (millis() - ms < 1000) return; // instead of delay(1000), keep cloud connection more responsive
//ms = millis();

  static float temp   = 0.0;
  static float umidRH = 0.0;
  static bool  stato  = false;
  if (sensor.read()) {
    temp = sensor.celsius();
    stato = (temp < setPoint);
    digitalWrite(pinRelay, stato);
  } 
  umidRH = ((analogRead(pinUmid) - vOffset) * vFactor) / (tBase - temp * tFactor);

  snprintf(env, sizeof(env), "s:%d,T:%.1f,P:%.1f,U:%.1f%%", stato, temp, setPoint, umidRH);
  Serial.print(env);

  delay(1000);						// less memory impact
}

int setTarget(String arg) {
  setPoint = arg.toFloat();
  return (setPoint + 0.5);			// poor man's rounding
}

Hello @ScruffR
as per your suggestion I changed the version from 1.4.4 to 1.0.0 and it no longer gives the error.
I had to add this line (pinMode (pinRelay, OUTPUT)) in the setup otherwise it didn’t work and do a rem on the variable (will not fit in region `APP_FLASH ') but I can fix this later.
I still have a problem with setting the setpoint from console or apps, in the setup we put 22.0, if I put 18 in the console the relay change state while if I set 25 it does not change state.
Thank you and good evening
Valentino

As per your own code, in order for the relay to change state sensor.read() must return true and the comparison (temp < setPoint) must change from the state corresponding to the current state of the relay.
Without knowing the state of these conditions it’s difficult to assess the cause.

What do the Serial.print() logs tell you about that?

In order to get back your Particle.variable() you could comment out the Serial.print() statement once you got your code doing what it’s supposed to do.
Also any variable you don’t need in the snprintf() output should free up some more space for other things you need.
But it’s a ride on the knives edge.

Going back to 0.7.0 will provide you with another decent extra chunk of space.

Hello @ScruffR
Thanks to this version everything works fine even the change of the values for the setpoint. I attach print screen of the serial print. The humidity calculation is not correct, as I had done in my calculation the humidity corresponded to that measured with both digital and analog hygrometers.
Anyway thanks for the support I wish you a good day.
Valentino

s:1,T:20.4,P:22.0,U:22748.9%
s:1,T:20.4,P:22.0,U:22620.1%
s:1,T:20.4,P:22.0,U:22594.3%
s:1,T:20.4,P:22.0,U:22723.2%
s:0,T:20.4,P:18.0,U:22980.9%
s:0,T:20.4,P:18.0,U:23058.2%
s:0,T:20.4,P:18.0,U:22723.2%
s:0,T:20.4,P:18.0,U:22800.5%
s:0,T:20.4,P:18.0,U:23084.0%
s:0,T:20.4,P:18.0,U:23135.6%
s:1,T:20.4,P:25.0,U:22671.6%
s:1,T:20.4,P:25.0,U:22697.4%
s:1,T:20.4,P:25.0,U:22929.4%
s:1,T:20.4,P:25.0,U:22620.1%

Could it be that there is a factor of 1 / 1000 missing?
Originally that variable was called UmidTRH which I didn’t quite understand, but looking at the numbers it seems to fit but would only have made sense if UmidTRH was an integer.

In your original code you also used UmidV which suggested to me that this would be some voltage reading and hence wouldn’t make much sense as I haven’t heard of any common device that uses that unit for humidity.
To save space I removed the intermediate calculation of UmidV and unified both formulas into one for relative humidity, also removing some calculation steps by incorporating other constants (like 4095) into the named constants.

Consequently, to get relative humidity in percent you’d need to change tBase and tFactor accordingly (1054.6 & 2.16).
Alternatively, to get your other reading (maybe absolute humidity as [g/m³]???) you’d remove the term [ / (tBase - temp * tFactor) ] from the calculation - also rename the variable appropriately (e.g. absUmid) and change the unit in the format string.

  absUmid = ((analogRead(pinUmid) - vOffset) * vFactor);
  snprintf(env, sizeof(env), "s:%d,T:%.1f°C,P:%.1f°C,U:%.1fg/m³", stato, temp, setPoint, absUmid);

This illustrates how important it would be to comment on the meaning of your variable names and formulas, so that uninitiated coders can make sense of what they see :wink:

1 Like

Hello @ScruffR
I made various measurements but your calculations are correct if we divide by 1000 (see attached printscreen), compared with a digital hygrometer it currently indicates 23%.
Thanks Valentino

s:1,T:21.0°C,P:22.0°C,U:22804.5g/m³
s:1,T:21.0°C,P:22.0°C,U:22153.4g/m³
s:1,T:20.9°C,P:22.0°C,U:22257.5g/m³
s:1,T:20.9°C,P:22.0°C,U:22153.4g/m³

So if you want percent (relative humidity) after all you should use this then

const float vOffset		=  620.3935;	// == 0.1515  * 4095
const float vFactor		=   26.0442;	// == 0.00636 * 4095 
const float tBase       = 1054.6000;	// origin to be documented  
const float tFactor     =    2.1600;	// origin to be documented

and

//absUmid = ((analogRead(pinUmid) - vOffset) * vFactor);
relUmid = ((analogRead(pinUmid) - vOffset) * vFactor) / (tBase - temp * tFactor);
snprintf(env, sizeof(env), "s:%d,T:%.1f°C,P:%.1f°C,U:%.1f%%", stato, temp, setPoint, relUmid);

Good morning @ScruffR
today made the suggested changes and now the values are right I added a line to compare the voltage measured with the voltmeter and the calculated one are the same.
I apologize for the delay on my replies to your suggestions, but Mr. Covid passed here leaving us his gifts.
Have a good day
Valentino

Tens 1.18
s: 1, T: 20.6 ° C, P: 22.0 ° C, U: 21.6%
Tens 1.18
s: 1, T: 20.6 ° C, P: 22.0 ° C, U: 21.5%
Tens 1.17
s: 1, T: 20.6 ° C, P: 22.0 ° C, U: 21.6%
1 Like

Just for documentation

const float vOffset		=  620.3935;	// == 0.1515  * 4095 from datasheeet Voltage Output Vout=Vsupply)(0.00636(sensor RH)+0.1515) typical at 25°C 
const float vFactor		=   26.0442;	// == 0.00636 * 4095 
const float tBase       = 1054.6000;	// From Datasheet Honeyweel HIH-5030 Temperature compensation True RH = (Sensor RH)/(1.0546 – 0.00216T), T in °C
const float tFactor     =    2.1600;	// From Datasheet Honeyweel HIH-5030 Temperature compensation True RH = (Sensor RH)/(1.0546 – 0.00216T), T in °C
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.