[Solved] error: 'isnan' was not declared in this scope isnan(n);

Post here all questions related to LibMaple core if you can't find a relevant section!
geostroud
Posts: 8
Joined: Tue Jun 16, 2020 5:39 pm
Answers: 1

[Solved] error: 'isnan' was not declared in this scope isnan(n);

Post by geostroud »

I am working on a project for a generic STM32F103C series board which uses a nRF24L01 transceiver module. It compiled just fine but I was having problem with transceiver modules. I had to take a two week break from the project. A couple of days ago, I decided to start work on the project again but when I went to rebuild the project using the Arduin 1.8.12 (Windows 8.1) IDE I get the following compiler error:

D:\Documents\Arduino\sketch_jun12a\sketch_jun12a.ino: In function 'void loop()':
sketch_jun12a:9:10: error: 'isnan' was not declared in this scope
isnan(n);

When I restarted work on the project, I installed all of the board and library updates were available on 2020/06/12. In an effort to resolve this problem I installed all library and board updates again today 2020/06/16. On both the dates there was a board update for the STM32F1xx/GD32F1xx boards that I installed. In an effort to simplify trouble shooting the problem I created the following simple sketch:

void setup() {
// put your setup code here, to run once:
}

void loop() {
// put your main code here, to run repeatedly:
double n = 0;
isnan(n);
}

I can successfully compile this simple script for the Arduino UNO, ESP32 and ESP8266 boards with no compile errors. However, as soon as I select board type "Generic STM32F103C Series" I get the above error. isnan() is a common function defined in math.h which is normally included from arduino.h. Can anyone help.
by geostroud » Sun Jun 21, 2020 2:47 pm
Version 2020.6.20 of the STM32F1xx/GD32F1xx board manager which just showed up yesterday or this morning appears to resolve this issue. Board manage version ...17 fails but version ...20 compiles without error. I can toggle this error on and off just by installing version 20 (no error) or installing any of the versions ...5.26 through 6.17 (fails). Therefore, If you would like to close this issue out, feel free. Thanks, GeoStroud.
Go to full post
geostroud
Posts: 8
Joined: Tue Jun 16, 2020 5:39 pm
Answers: 1

Re: error: 'isnan' was not declared in this scope isnan(n);

Post by geostroud »

I went back through the board updates for the "STM32F1xx/GD32F1XX boards". This issue starts with version 2020.2.26. If I revert back to the 2020.5.18 version of the board the sketch compiles without error.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: error: 'isnan' was not declared in this scope isnan(n);

Post by stevestrong »

Can you please indicate the correct date from which the issue starts and which version is working?
Because I just tried your example with the latest (Roger's libmaple) core version and it compiles error free.
geostroud
Posts: 8
Joined: Tue Jun 16, 2020 5:39 pm
Answers: 1

Re: error: 'isnan' was not declared in this scope isnan(n);

Post by geostroud »

If you check the update I posted, you will find the information you are requesting.
geostroud
Posts: 8
Joined: Tue Jun 16, 2020 5:39 pm
Answers: 1

Re: error: 'isnan' was not declared in this scope isnan(n);

Post by geostroud »

Sorry, I see that I made a typo. 2020.5.18 works. Versions 2020.5.26 thru 2020.6.16 fail.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: error: 'isnan' was not declared in this scope isnan(n);

Post by stevestrong »

This error is only shown with the original 4.8.3 GCC compiler version. Because I use 7.2.1, this was not visible.

The solution is to insert:

Code: Select all

using namespace std;
before setup().
I just committed a fix in the repo.
Please check out the latest version and let me know if it works.
geostroud
Posts: 8
Joined: Tue Jun 16, 2020 5:39 pm
Answers: 1

Re: error: 'isnan' was not declared in this scope isnan(n);

Post by geostroud »

The latest version that shows up as of today 06/19/2020 is version 2020.6.17 and it down resolve the problem. While I created a simple test sketch to illustrate the issue, the actual sketch that I am working on uses the BME280 library and the library uses the isnan() function. Therefore, while inserting the suggested include and using statement while circumventing the issue with the test sketch, it does not resolve the issue with my real sketch as I would have to locate and modify the routines using this function. They are not mine to modify.

Also, I as a user of the arduino IDE do not control what level of the GCC compiler is used. I am not even sure when and were the proper CC compiler is installed and configured.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: error: 'isnan' was not declared in this scope isnan(n);

Post by stevestrong »

Which BME280 library? Can you post a link to that?
And an example sketch using that library would be also helpful.
geostroud
Posts: 8
Joined: Tue Jun 16, 2020 5:39 pm
Answers: 1

Re: error: 'isnan' was not declared in this scope isnan(n);

Post by geostroud »

BME280 by Tyler Glenn Version 2.3.0
https://github.com/finitespace/BME280
geostroud
Posts: 8
Joined: Tue Jun 16, 2020 5:39 pm
Answers: 1

Re: error: 'isnan' was not declared in this scope isnan(n);

Post by geostroud »

Sketch (STM_WS.ino):

Code: Select all

/*
STM_WS.ino

Code for Weather Station that reports temperature, humidity, 
barometric pressure and rainfall.  Values are reported when
requested by the base station.  The rain fall is reset after
each report which makes it the responcibility of the base station
code to track accumulation over time.

Platform: STM32F103C8
Author:   George Stroud
Created:  Feb 27, 2020.
Last Updated: Apr 08, 2020 (V0.3).

Connecting the nRF24L01+
Transceiver   -> STM32F102C
---------------------------
GND           -> GND
VCC           -> 3.3V
CE            -> PB0
CSN           -> PA4
SCK           -> PA5
MOSI          -> PA7
MISO          -> PB6

Connecting the BME280 Sensor:
Sensor              ->  STM32F103C
----------------------------------
Vin (Voltage In)    ->  3.3V
Gnd (Ground)        ->  Gnd
SDA (Serial Data)   ->  PB7 STM32F103C
SCK (Serial Clock)  ->  PB6 STM32F103C

 Connecting the Rain Gauage
 Sensor     -> STM32F103C
----------------------------------
VCC         -> 3.3v
GND         -> GND
Signal      -> PC13

 */

#include <BME280I2C.h>
#include <Wire.h>
#include <SPI.h>
#include <RF24-STM.h>
#include <WS_Lib.h> // In D:\Documents\Arduino\libraries\GeoS_Library
#include <math.h>
using namespace std;

#define SERIAL_BAUD 115200
#define LedPin PC13
#define RGPin PC15

BME280I2C bme;

RF24 radio(PB0,PA4);

data wsData;
_cmd wsCmd;
volatile unsigned long rainIntCnt = 0;

// -----------------------------------------------------------------------------
// SETUP   SETUP   SETUP   SETUP   SETUP   SETUP   SETUP   SETUP   SETUP
// -----------------------------------------------------------------------------
void setup()
{
  pinMode(LedPin, OUTPUT);  
  Serial.begin(SERIAL_BAUD);

  while(!Serial) {} // Wait

  Wire.begin();

  while(!bme.begin()) {
    Serial.println("Could not find BME280 sensor!");
    delay(1000);
  } // end "while..."

  Serial.print("chipModel:");
  Serial.println(bme.chipModel());
 
  switch(bme.chipModel()) {
     case BME280::ChipModel_BME280:
       Serial.println("Found BME280 sensor! Success.");
       break;
     case BME280::ChipModel_BMP280:
       Serial.println("Found BMP280 sensor! No Humidity available.");
       break;
     default:
       Serial.println("Found UNKNOWN sensor! Error!");
  } // end "switch..."
 
  // Initiate the radio object
  radio.begin();

  // Set the transmit power to the mid power level
  radio.setPALevel(wsPwrLvl);

  // Set tje s[eed pf tje transmission to the 250KBS
  radio.setDataRate(wsDataRate);

  // Use a channel unlikely to be used by Wifi, or other 2.4GHz devices
  radio.setChannel(wsChan);

  // Open a writing and reading pipe on each radio, with opposite addresses
  radio.openReadingPipe(1, wsRdPipe);
  radio.openWritingPipe(ws1TxPipe);

  // Give the receiver a chance
  radio.setRetries(10, 10);

  // Auto ackknowledgment of a transmission
  radio.setAutoAck(true);
  
  // Listen for Base station request for data
  radio.startListening();

  // Debugging information
  radio.printDetails();
  attachInterrupt(digitalPinToInterrupt(RGPin), RainGaugeISR, RISING);
  rainIntCnt = 0;  // Clear rain gauge interrupt count;
  
  digitalWrite(LedPin,LOW);  
  Serial.println("STM:WS - Exiting setup");
} // end "setup"

// -----------------------------------------------------------------------------
// LOOP   LOOP   LOOP   LOOP   LOOP   LOOP   LOOP   LOOP   LOOP   LOOP   LOOP
// -----------------------------------------------------------------------------
void loop()
{
   // Check if command received
   if (radio.available())
   {
      // Get the command/request
      delay(50);
      if (radio.read(&wsCmd, sizeof(wsCmd))) {

         Serial.println("Read command successful");
         printCmd('R', &wsCmd);

         if (wsCmd.cmdID == RETRIEVE) {
            getData(&wsData); 
            
            if (xmitData(&wsData))  // Xmit data to base station
               rainIntCnt -= wsData.intCnt; // Adjust rain guage interrupt

            printData(&wsData);
         } // end "if (wsCmd.cmdID..."

      } else {  // radop/read(...) failed

         Serial.println("Read command failed");

      } // end "if (radio.read(...)"

   } // end "if (radio.available())"

}  // end "loop"

//////////////////////////////////////////////////////////////////

void getData(data *wsData)
{
   Serial.println("getData called");
   BME280::TempUnit tempUnit(BME280::TempUnit_Fahrenheit);
   BME280::PresUnit presUnit(BME280::PresUnit_inHg);

   bme.read(wsData->pres, wsData->temp, wsData->hum, tempUnit, presUnit);
   wsData->intCnt = rainIntCnt;
   wsData->rain = (rainFactor * wsData->intCnt);

} // end "getData..."

bool xmitData(data *wsData)
{
   Serial.println("xmitData called");
   bool state = digitalRead(LedPin);
   digitalWrite(LedPin, !state);

   // Transmit data to base station
   radio.stopListening();  // Ensure we have stopped listening
   if (radio.write(wsData, sizeof(*wsData))) {
      Serial.println("TX: ACK");
      radio.startListening();
      return true;
   } else {
      Serial.println("TX: No ACK");
      radio.startListening();
      return false;
   } // end "if (!radio.write..."

} // end "xmitData..."

void RainGaugeISR()
{
   rainIntCnt++;
}
My library routine (WS_Lib.h):

Code: Select all

// Last Updated: 2020/04/29  (V0.3)
// WS_Lib.h
#ifndef MY_WS_H 
#define MY_WS_H

#define wsRdPipe   0xB3B4B5B601 // Pipe on which ws base station transmits
#define ws1TxPipe  0xB3B4B5B602 // Pipe on which ws1 THBp transmits
#define ws2TxPipe  0xB3B4B5B603 // Pipe on which ws2 Anamometer transmits
#define wsChan     125          // Transmission channel
#define wsTimeOut  5000         // Base Station will wait up to 5 seconds 
                                //    for weather statiion reply
#define wsDataRate RF24_250KBPS // RF24_250KBPS, RF24_1MBPS, RF24_2MBPS
#define wsPwrLvl   RF24_PA_MAX  // RF24_LOW, RF24_MAX

#include <time.h>

struct data {
  float temp;               // Temperature
  float hum;                // Humidity
  float pres;               // Barometric Pressure
  float rain;               // Rain Fall since last read
  unsigned long intCnt;     // Count of interrupts from rain gauge (fcr calabration)
}; // end "data"

#define RETRIEVE 'R'        // Retrieve and return Weather Station Data.
struct _cmd {
   char cmdID;              // Command for Weather Station.  Currently only 'F' for fetch data supported.
   char subCmd;             // Optional sub-command,  Currently no sub-commands are supported.
}; // end "_cmd"

// char MyTm[18] = 0;

#define rainFactor .0158    // Rain Fall per sensor bucket tip

//////////////////////////////////////////////////////////////////
#ifdef _RPI_

void MyTime(char *logtm)
{
   time_t mytime;
	struct tm *mytm;

  	mytime = time(NULL);
  	mytm = localtime(&mytime);
   sprintf(logtm,"%4d-%02d-%02d %02d:%02d",
           1900 + mytm->tm_year, mytm->tm_mon, 
           mytm->tm_mday, mytm->tm_hour, mytm->tm_min);
} // end "MyTime()"

void printData(char *logtm, data *wsData)
{
   printf("%s  Temp: %.2fF\tHumidity: %.2f% RH\tPressure: %.2f  inHg"
          "\tRain: %.2f in (%u)\n", logtm, wsData->temp, wsData->hum, 
          wsData->pres, wsData->rain, wsData->intCnt);
} //end "printData..."

void printCmd(char *logtm, _cmd *wsCmd)
{ 
   printf("%s CMD Received: CMD=%c, SubCMD=%c\n", logtm,  wsCmd->cmdID, wsCmd->subCmd);
} // end "printCmd..."

void logData(char *logfile, char *logtm, data& wsData)
{
   FILE *filePtr;
   filePtr = fopen(logfile,"a");
   if (filePtr == NULL) {
      fprintf(stderr, "Failed to open log file.\n");
   } else {
      fprintf(filePtr, "%s,%.2f,%.2f,%.2f,%.2f,%u\n",
              logtm, wsData.temp, wsData.hum, wsData.pres,
              wsData.rain, wsData.intCnt);
      fclose(filePtr);
   } // end "If (filePtr..."
} // end "logData(..."

#else

void printData(data *wsData)
{
   Serial.print("Temp: ");
   Serial.print(wsData->temp);
   Serial.print("F");
   Serial.print("\tHumidity: ");
   Serial.print(wsData->hum);
   Serial.print("% RH");
   Serial.print("\tPressure: ");
   Serial.print(wsData->pres);
   Serial.print(" inHg");
   Serial.print("\tRain: ");
   Serial.print(wsData->rain);
   Serial.print(" in (");
   Serial.print(wsData->intCnt);
   Serial.println(")");
} //end "printData..."

void printCmd(char lbl, _cmd *wsCmd)
{ 
   if (lbl=='S')
      Serial.print("CMD Sent: CMD=");
   else if (lbl=='R')
      Serial.print("CMD Received: CMD=");
   else
      Serial.print("CMD Struct: CMD=");
   Serial.print(wsCmd->cmdID);
   Serial.print(", SubCMD=");
   Serial.println(wsCmd->subCmd);
} // end "printCmd..."
#endif

#endif // MY_WS_H
Post Reply

Return to “General discussion”