-->
Page 1 of 1

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

PostPosted: Sat Jun 02, 2018 4:31 am
by MajorBob
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:

Code: Select all
/*
//#define DEBUG
#define DEBUG_NO_PAGE_FADE
#define DEBUG_NO_TOUCH

#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) {
  displayTime();
}

//
// setup
//

void setup() {
  #ifdef DEBUG
    Serial.begin(9600);
  #endif
  
  nexSerial.begin(9600);

  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");

  delay(startupDelay);

  dht.begin();  
  
  displayFadeIn(0, displayStartupDimValue, dimStartupDelay);

  connectToWifi();
  clockUDP.begin(localPort);
  getTimeFromServer();

  if (timeServerConnected)
    displayTime();
    
  displayDate();
  displaydht();

  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");
  #endif
}

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

And this is the error that I'm getting:

Code: Select all
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

Alex