Code error suddenly appeared which has worked for 6 months

Hi,
I have been running this code for 8 months. It monitors the temperature in a very old and large church. We decided to add 3 more sensors to see if we can lower heat. I copied code from the successfully running sensors. I went to check code after changing ThingSpeak IDS. And got an error. I went back tot he original code that has been running and did code check on that and have the same error. I am at a loss as to what is happening as the original sensor is happily sending back data. I will add that I am barely understanding the code as I cut and pasted from other projects.

The error is:

This is expanded error:
Processing temperaturechurch.ino
Checking library Adafruit_DHT…
Checking library ThingSpeak…
Installing library Adafruit_DHT 0.0.2 to lib/Adafruit_DHT …
Installing library ThingSpeak 1.5.1 to lib/ThingSpeak …
Library ThingSpeak 1.5.1 installed.
Library Adafruit_DHT 0.0.2 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/temperaturechurch.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.2 -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/Adafruit_DHT/src -Ilib/ThingSpeak/src -I. -MD -MP -MF …/build/target/user/platform-0-ltosrc/temperaturechurch.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=1404 -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/temperaturechurch.o src/temperaturechurch.cpp
temperaturechurch.ino: In function ‘void setup()’:
temperaturechurch.ino:40:3: error: ‘Cellular’ was not declared in this scope
In file included from …/wiring/inc/spark_wiring.h:50:0,
from ./inc/application.h:40,
from src/temperaturechurch.cpp:1:
temperaturechurch.ino: In lambda function:
temperaturechurch.ino:42:15: error: ‘Cellular’ is not captured
…/wiring/inc/spark_wiring_system.h:462:70: note: in definition of macro ‘waitFor’
#define waitFor(condition, timeout) System.waitCondition({ return (condition)(); }, (timeout))
^
…/wiring/inc/spark_wiring_system.h:462:59: note: the lambda has no capture-default
#define waitFor(condition, timeout) System.waitCondition({ return (condition)(); }, (timeout))
^
temperaturechurch.ino:42:7: note: in expansion of macro ‘waitFor’
temperaturechurch.ino:40:3: note: ‘Cellular’ declared here
In file included from …/wiring/inc/spark_wiring.h:50:0,
from ./inc/application.h:40,
from src/temperaturechurch.cpp:1:
…/wiring/inc/spark_wiring_system.h: In instantiation of ‘static bool SystemClass::waitConditionWhile(Condition, While) [with Condition = setup()::<lambda()>; While = SystemClass::waitCondition(Condition, system_tick_t) [with Condition = setup()::<lambda()>; system_tick_t = long unsigned int]::<lambda()>]’:
…/wiring/inc/spark_wiring_system.h:257:34: required from ‘static bool SystemClass::waitCondition(Condition, system_tick_t) [with Condition = setup()::<lambda()>; system_tick_t = long unsigned int]’
temperaturechurch.ino:42:7: required from here
…/wiring/inc/spark_wiring_system.h:245:39: error: could not convert ‘_condition.setup()::<lambda()>()’ from ‘void’ to ‘bool’
while (_while() && !_condition()) {
^
…/wiring/inc/spark_wiring_system.h:245:28: error: in argument to unary !
while (_while() && !_condition()) {
^
…/wiring/inc/spark_wiring_system.h:248:27: error: void value not ignored as it ought to be
return _condition();
^
…/build/module.mk:277: recipe for target ‘…/build/target/user/platform-0-ltosrc/temperaturechurch.o’ failed
make[1]: *** […/build/target/user/platform-0-ltosrc/temperaturechurch.o] Error 1
make[1]: Leaving directory ‘/firmware/user’
…/build/recurse.mk:11: recipe for target ‘user’ failed
make: *** [user] Error 2
Hide raw
Ready.

And the code that I think it is referencing is this:

//set timer soft delay

inline void softDelay(uint32_t t) {
  for(uint32_t ms = millis(); millis() - ms < t; Particle.process());

}
void setup() {
    
//line 34 5o 36  added in order to make sure cellular module working see https://community.particle.io/t/cellular-network-unhealthy/47802/6
  Cellular.on(); // just to be on the safe side due to open issue
  Cellular.connect();
  if (waitFor(Cellular.ready, 300000)) { // wait up to 5 minutes for the connection to establish

    // Connect to ThingSpeak
    ThingSpeak.begin(client);

    // Give power to the sensor
    pinMode(DHT_5V_PIN, OUTPUT);
    pinMode(DHT_GROUND_PIN, OUTPUT);
    digitalWrite(DHT_5V_PIN, HIGH);
    digitalWrite(DHT_GROUND_PIN, LOW);

    // Wait for the sensor to stabilize
    softDelay(5000);



    // Initialize sensor
    dht.begin();

    // Read Sensor
    double temperature = dht.getTempCelcius();
    double humidity = dht.getHumidity();
    //Temperature here to see if code was upated being sent to ThinkSpeak
    double tempf = dht.getTempFarenheit();



    // Update the 2 ThingSpeak fields with the new data
    ThingSpeak.setField(1, (float)temperature);
    ThingSpeak.setField(2, (float)humidity);
    ThingSpeak.setField(3, (float)tempf);

    // Write the fields that you've set all at once.
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    
     // Give time for the message to reach ThingSpeak
     softDelay(5000);
  }

The Cellular not declared message suggest you may not be targeting a cellular device (Electron or Boron).

Your code above also only shows a setup() function but no loop() and even that function is lacking a closing curly brace.

Hmm,
Very odd as this is the code that in theory is on the Particle Electrons that have been running for the last number of months.
Is it possible the WebIDE code got corrupted somehow?

Just to be sure I have confused you. That was a cut and paste of part of the coded. This is the entire code with API key with “xxxx”

// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>

// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>

// Sensor type
#define DHTTYPE DHT22    	// DHT 22 (AM2302)

// DHT22 sensor pinout:
// Pin 1 (on the left): +3.3V
// Pin 2: output
// Pin 4 (on the right): GROUND
#define DHT_5V_PIN D1
#define DHT_SENSOR_PIN D2
#define DHT_GROUND_PIN D4

DHT dht(DHT_SENSOR_PIN, DHTTYPE);

/* Thingspeak */
TCPClient client;
unsigned long myChannelNumber = XXXXX;
const char * myWriteAPIKey = "XXXXXX";

//set timer soft delay

inline void softDelay(uint32_t t) {
  for(uint32_t ms = millis(); millis() - ms < t; Particle.process());

}
void setup() {
    
//line 34 5o 36  added in order to make sure cellular module working see https://community.particle.io/t/cellular-network-unhealthy/47802/6
  Cellular.on(); // just to be on the safe side due to open issue
  Cellular.connect();
  if (waitFor(Cellular.ready, 300000)) { // wait up to 5 minutes for the connection to establish

    // Connect to ThingSpeak
    ThingSpeak.begin(client);

    // Give power to the sensor
    pinMode(DHT_5V_PIN, OUTPUT);
    pinMode(DHT_GROUND_PIN, OUTPUT);
    digitalWrite(DHT_5V_PIN, HIGH);
    digitalWrite(DHT_GROUND_PIN, LOW);

    // Wait for the sensor to stabilize
    softDelay(5000);



    // Initialize sensor
    dht.begin();

    // Read Sensor
    double temperature = dht.getTempCelcius();
    double humidity = dht.getHumidity();
    //Temperature here to see if code was upated being sent to ThinkSpeak
    double tempf = dht.getTempFarenheit();



    // Update the 2 ThingSpeak fields with the new data
    ThingSpeak.setField(1, (float)temperature);
    ThingSpeak.setField(2, (float)humidity);
    ThingSpeak.setField(3, (float)tempf);

    // Write the fields that you've set all at once.
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    
     // Give time for the message to reach ThingSpeak
     softDelay(5000);
  }
    
    
  

    // Sleep for 15 changed to a minute save data costs, 15 gives a 20 minute interval.
    //Change back to 15 and see what that gives 02202019 change to 5 to test sleep not messing up connections
    //Line 81 to 82 added for cellular potential see link lin 33
    Cellular.off();
    for(uint32_t ms = millis(); millis() - ms < 500; Particle.process());
    System.sleep(SLEEP_MODE_DEEP, 20 * 60);
}

void loop() {
    // This will run because the system is sleeping
      
}

When you have this in Web IDE you can simply post a SHARE THIS REVISION link.

A bit of asynchronous communication.
I just pasted the code before I saw your response

For me that code builds just fine
https://go.particle.io/shared_apps/5dd97e87cad9090022140f8c link deactivated

I notice my Adafruit_DHT is 0.0.2 and yours is 0.0.4 in your code. I changed that and that did not work.

Have you tried compiling my version? There is no need to change yours to mimik my working project, just take it as is and build that.

If that doesn't work for you I come back to my first assessment that you many not have set the Web IDE to target an Electron (I built for Electron device OS v1.4.2)

We wouldn't know, but that's why posting a link to your revision is usually the way to go. You wouldn't have to explain all the details and anybody testing wouldn't have to manually import all the required libraries. Just copy the revision, build and you're done.

I am trying to get by head around what I am doing so I don’t accidentally flash to the working devices which at the moment are 60 miles away!
When I go to Particle Devices in the WebIDE and I point to the device I have in front of me now I can signal it successfully. However, the Device OS is an old version which I thought I could fix when I flashed the code to it.
When I link your code the compile button is greyed out on the WebIDE.
Where do I set the IDE target?
I appreciate your help!

You mean you have the golden star set next to that device?
Signallying the device will only tell you whether you got the correct device and if it's online, it will not set this device as the targed for your build or flash. For that you have to click the star on the left of the device name.

When you open someone elses revision you need to hit the COPY THIS APP button to create a copy for you to work on.

Ok, I now think I get what you are saying. I clicked to the star on the left of the device list to the device I am working on. My program compiled correctly! I am a still confused as it seems that you can never have all starts unclicked. I got confused as everything compiled a few days ago. But the good news it compiled correctly now. Now on to flashing.
I just loaded your code to test my theory. The only one it is letting me highlight is the current one I set up. I am thinking this is due to the fact that the original 2 are sleeping and the other new ones are not turned on. Does that make sense?
Also if you Share a Link with your code, I assume you do this after you take out the API codes.

So many things to learn!
Thanks

What do you mean by highlighting?
You can select and build for any device whether online or offline but off course you won't be able to flash a sleeping device OTA.

That depends on your confidentiality needs :wink:
But yes, if I happened to share a code with my tokens I'd take them out, but I'm usually on the receiving end.

I mean to highlight the star. I am beginning to think this may have something to with my WebIDE as I just went to it and now it lets me click on the other stars where as before it was not letting me change.

Well, our churche’s heating bill thanks you for your help! - and I do to since I came up with this crazy idea of seeing the temperatures through out the building and knew it was possible but had not idea how to do it. Now I have to figure out how to pull in the outside temperature to write to ThingSpeak!

1 Like

Do you have the correct device type selected in the Web IDE? I get this error if I try to compile code and I do not have a device selected under devices.

You are correct. The star wasn’t updating on the WEB IDE for some reason but now is working.