os_timer_t error - expected ',' or ';' before 'ETSTimer'

Hi all, I’m a first time poster here and new to programming… I’ve probably bit off more than I can chew but I do love a challenge!

My project is a weather forecast display using a NodeMCU ESP8266 12E with 2.8" Nextion screen and DHT22 sensor. The code is originally from someone who has made the same project but using a BME280 sensor. I think I have adjusted the code correctly for the different sensor but isn’t my issue. The problem I’m having is with the os_timer_t function. The error I’m getting seems to be telling that there is an issue in one of the libraries and I have no idea how to fix it. I have tried renaming the timer and rolling back the library to previous versions, but that doesn’t seem to have changed anything. Can any of you shed a light on my predicament?

This is the code:

//#define DEBUG

#define nexSerial Serial1

// include libraries

#include <Wire.h>
#include <SPI.h>                                // I2C library
#include <DHT.h>                                // DHT library
#include <DHT_U.h>                              // DHT unified library
#include <ArduinoJson.h>                        // https://github.com/bblanchon/ArduinoJson
#include <ESP8266WiFi.h>                        // WiFi library
#include <WiFiUdp.h>                            // Udp library
#include <TimeLib.h>                            // Time library

extern "C" {
  #include "user_interface.h"

// settings for WiFi connection

char * ssid     = "AlexMassguest";         // WiFi SSID
char * password = "fg6SrxywH6pv";          // WiFi password

unsigned int localPort = 2390;                  // local port to listen for UDP packets
IPAddress timeServerIP;                         // IP address of random server 
const char* ntpServerName = "pool.ntp.org";     // server pool
byte packetBuffer[48];                          // buffer to hold incoming and outgoing packets
int timeZoneoffsetGMT = 0;                      // offset from Greenwich Meridan Time
boolean DST = true;                             // daylight saving time
WiFiUDP clockUDP;                               // initialize a UDP instance

// settings for the openweathermap connection
// sign up, get your api key and insert it below

char * servername ="api.openweathermap.org";          // remote server with weather info
String APIKEY = "9818c9658512008e2e87e6493eabc967";   // personal api key for retrieving the weather data

const int httpPort = 80;
String result;
int cityIDLoop = 0;

// a list of cities you want to display the forecast for
// get the ID at https://openweathermap.org/
// type the city, click search and click on the town
// then check the link, like this: https://openweathermap.org/city/5128581
// 5128581 is the ID for New York

String cityIDs[] = {
  "2636389"   // Swindon

// settings

int startupDelay = 1000;                      // startup delay
int loopDelay = 3000;                         // main loop delay between sensor updates

int timeServerDelay = 1000;                   // delay for the time server to reply
int timeServerPasses = 4;                     // number of tries to connect to the time server before timing out
int timeServerResyncNumOfLoops = 3000;        // number of loops before refreshing the time. one loop takes approx. 28 seconds
int timeServerResyncNumOfLoopsCounter = 0;
boolean timeServerConnected = false;          // is set to true when the time is read from the server

int maxForecastLoop = 1;                      // number of main loops before the forecast is refreshed, looping through all cities
int weatherForecastLoop = 0;
int weatherForecastLoopInc = 1;

int displayStartupDimValue = 30;              // startup display backlight level
int displayDimValue = 150;                    // main display backlight level
int displayDimStep = 1;                       // dim step
int dimStartupDelay = 50;                     // delay for fading in
int dimPageDelay = 0;                         // delay for fading between pages

// Constants

#define DHTPIN A0                             //Connected pin
#define DHTTYPE DHT22                         //DHT22

// initialize variables

int page = 0;

float hum;
float temp;

String command;
String doubleQuote = "\"\"";

// initialize sensor

DHT dht(DHTPIN, DHTTYPE)                      //Initialise sensor

// initialize timer

os_timer_t secTimer;

void timerDisplayTime(void *pArg) {

// setup

void setup() {
  #ifdef DEBUG

  printNextionCommand("dims=" + String(0));         // set initial startup backlight value of the Nextion display to 0
  printNextionCommand("dim=" + String(0));          // also set the current backlight value to 0
  printNextionCommand("page 0");


  displayFadeIn(0, displayStartupDimValue, dimStartupDelay);


  if (timeServerConnected)

  os_timer_setfn(&secTimer, timerDisplayTime, NULL);
  if (timeServerConnected)
    os_timer_arm(&secTimer, 1000, true);
  displayFadeIn(displayStartupDimValue, displayDimValue, dimStartupDelay / 2);

  #ifdef DEBUG
    Serial.println("Starting main loop");

I had to reduce the code to mostly the affected area.

And this is the error that I’m getting:

In file included from C:\Users\Alex\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0/tools/sdk/include/user_interface.h:9:0,

                 from C:\Users\Alex\Documents\Arduino\Weather_forecast_DHT22\Weather_forecast_DHT22.ino:42:

C:\Users\Alex\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0/tools/sdk/include/os_type.h:16:21: error: expected ',' or ';' before 'ETSTimer'

 #define os_timer_t  ETSTimer


C:\Users\Alex\Documents\Arduino\Weather_forecast_DHT22\Weather_forecast_DHT22.ino:134:1: note: in expansion of macro 'os_timer_t'

 os_timer_t secTimer;


C:\Users\Alex\Documents\Arduino\Weather_forecast_DHT22\Weather_forecast_DHT22.ino: In function 'void setup()':

Weather_forecast_DHT22:171: error: 'secTimer' was not declared in this scope

   os_timer_setfn(&secTimer, timerDisplayTime, NULL);


In file included from C:\Users\Alex\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/pgmspace.h:13:0,

                 from C:\Users\Alex\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/Arduino.h:240,

                 from sketch\Weather_forecast_DHT22.ino.cpp:1:

C:\Users\Alex\Documents\Arduino\Weather_forecast_DHT22\Weather_forecast_DHT22.ino: In function 'void loop()':

Weather_forecast_DHT22:190: error: 'secTimer' was not declared in this scope

       os_timer_arm(&secTimer, 1000, true);


C:\Users\Alex\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0/tools/sdk/include/osapi.h:37:49: note: in definition of macro 'os_timer_arm'

 #define os_timer_arm(a, b, c) ets_timer_arm_new(a, b, c, 1)


exit status 1
'secTimer' was not declared in this scope

Thanks in advance


You are referring to a variable "secTimer" that does not exist.

Maybe it is defined as part of the core for some board which the code you're using was written for - but not the board you're using, or maybe you copy/pasted some parts of the code but missed others. The fact that it's calling a function called os_timer_arm when you're using an ESP8266 (which is not an ARM processor) makes me suspect the first case.

The person who wrote the code was using the same board.

"We can define the user function to be called when the timer fires using the os_timer_setfn()
function. Note that we can only set the callback function when the timer is disarmed.

When ready, we can arm the timer so that it starts ticking and fires when ready. We do this using
the os_timer_arm() function." Neil Kolban - ESP8266 book

But when I check the file that the #define os_timer_t ESTTimer error is in (as that seems to be the root of the problem) and compare it against the online version, there is no differences.

My file:

* copyright (c) Espressif System 2010 *
* mapping to ETS structures *

#ifndef _OS_TYPES_H_

#define _OS_TYPES_H_

#include "ets_sys.h"

#define os_signal_t ETSSignal

#define os_param_t  ETSParam

#define os_event_t ETSEvent

#define os_task_t ETSTask

#define os_timer_t  ETSTimer

#define os_timer_func_t ETSTimerFunc


I think you have a semicolon missing from the previous line of code:

DHT dht(DHTPIN, DHTTYPE); //Initialise sensor

// // initialize timer //

os_timer_t secTimer;

westfw: I think you have a semicolon missing from the previous line of code:

Thank you, I have tried that and it added a DHT error which I recognised from working just the DHT code before this project.