From 5164af7edc1cb7a407ba21f17d49e1560eb1def7 Mon Sep 17 00:00:00 2001 From: Olivier Date: Tue, 19 Sep 2017 22:48:54 +0200 Subject: [PATCH] ESP8266: Fix example compilation error (#932) --- .../AirQualitySensor/AirQualitySensor.ino | 2 +- .../BatteryPoweredSensor.ino | 2 +- examples/CO2Sensor/CO2Sensor.ino | 8 +++--- examples/DustSensor/DustSensor.ino | 2 +- examples/DustSensorDSM/DustSensorDSM.ino | 16 +++++------ .../EnergyMeterPulseSensor.ino | 27 +++++++++---------- examples/LightSensor/LightSensor.ino | 2 +- examples/MockMySensors/MockMySensors.ino | 4 +-- examples/MotionSensor/MotionSensor.ino | 2 +- .../MotionSensorRS485/MotionSensorRS485.ino | 2 +- examples/PHSensor/PHSensor.ino | 2 +- .../SecurityPersonalizer.ino | 8 +++--- examples/SoilMoistSensor/SoilMoistSensor.ino | 2 +- examples/UVSensor/UVSensor.ino | 6 ++--- examples/VibrationSensor/VibrationSensor.ino | 2 +- .../WaterMeterPulseSensor.ino | 24 ++++++++--------- 16 files changed, 54 insertions(+), 57 deletions(-) diff --git a/examples/AirQualitySensor/AirQualitySensor.ino b/examples/AirQualitySensor/AirQualitySensor.ino index 93fd8be..9986272 100644 --- a/examples/AirQualitySensor/AirQualitySensor.ino +++ b/examples/AirQualitySensor/AirQualitySensor.ino @@ -63,7 +63,7 @@ #define GAS_CO (1) #define GAS_SMOKE (2) /*****************************Globals***********************************************/ -unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) +uint32_t SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) //VARIABLES float Ro = 10000.0; // this has to be tuned 10K Ohm int val = 0; // variable to store the value coming from the sensor diff --git a/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino b/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino index e271c5f..1b58269 100644 --- a/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino +++ b/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino @@ -41,7 +41,7 @@ int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point -unsigned long SLEEP_TIME = 900000; // sleep time between reads (seconds * 1000 milliseconds) +uint32_t SLEEP_TIME = 900000; // sleep time between reads (seconds * 1000 milliseconds) int oldBatteryPcnt = 0; void setup() diff --git a/examples/CO2Sensor/CO2Sensor.ino b/examples/CO2Sensor/CO2Sensor.ino index 73670ef..7b3bf2e 100644 --- a/examples/CO2Sensor/CO2Sensor.ino +++ b/examples/CO2Sensor/CO2Sensor.ino @@ -1,4 +1,4 @@ -/* +/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -52,7 +52,7 @@ #define CHILD_ID_AIQ 0 #define AIQ_SENSOR_ANALOG_PIN 6 -unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds) +uint32_t SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds) float valAIQ =0.0; float lastAIQ =0.0; @@ -78,12 +78,12 @@ void presentation() void loop() { - //unsigned long duration = pulseIn(AIQ_SENSOR_ANALOG_PIN, HIGH); + //uint32_t duration = pulseIn(AIQ_SENSOR_ANALOG_PIN, HIGH); while(digitalRead(AIQ_SENSOR_ANALOG_PIN) == HIGH) { ; } //wait for the pin to go HIGH and measure HIGH time - unsigned long duration = pulseIn(AIQ_SENSOR_ANALOG_PIN, HIGH); + uint32_t duration = pulseIn(AIQ_SENSOR_ANALOG_PIN, HIGH); //Serial.print(duration/1000); Serial.println(" ms "); //from datasheet diff --git a/examples/DustSensor/DustSensor.ino b/examples/DustSensor/DustSensor.ino index 077276c..1ccf552 100644 --- a/examples/DustSensor/DustSensor.ino +++ b/examples/DustSensor/DustSensor.ino @@ -52,7 +52,7 @@ #define CHILD_ID_DUST 0 #define DUST_SENSOR_ANALOG_PIN 1 -unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds) +uint32_t SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds) //VARIABLES int val = 0; // variable to store the value coming from the sensor float valDUST =0.0; diff --git a/examples/DustSensorDSM/DustSensorDSM.ino b/examples/DustSensorDSM/DustSensorDSM.ino index b4c5eab..7564973 100644 --- a/examples/DustSensorDSM/DustSensorDSM.ino +++ b/examples/DustSensorDSM/DustSensorDSM.ino @@ -46,18 +46,18 @@ #define DUST_SENSOR_DIGITAL_PIN_PM10 6 #define DUST_SENSOR_DIGITAL_PIN_PM25 3 -unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds) +uint32_t SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds) //VARIABLES int val = 0; // variable to store the value coming from the sensor float valDUSTPM25 =0.0; float lastDUSTPM25 =0.0; float valDUSTPM10 =0.0; float lastDUSTPM10 =0.0; -unsigned long duration; -unsigned long starttime; -unsigned long endtime; -unsigned long sampletime_ms = 30000; -unsigned long lowpulseoccupancy = 0; +uint32_t duration; +uint32_t starttime; +uint32_t endtime; +uint32_t sampletime_ms = 30000; +uint32_t lowpulseoccupancy = 0; float ratio = 0; long concentrationPM25 = 0; long concentrationPM10 = 0; @@ -88,7 +88,7 @@ void presentation() void loop() { - //get PM 2.5 density of particles over 2.5 μm. + //get PM 2.5 density of particles over 2.5 µm. concentrationPM25=(long)getPM(DUST_SENSOR_DIGITAL_PIN_PM25); Serial.print("PM25: "); Serial.println(concentrationPM25); @@ -99,7 +99,7 @@ void loop() lastDUSTPM25 = ceil(concentrationPM25); } - //get PM 1.0 - density of particles over 1 μm. + //get PM 1.0 - density of particles over 1 µm. concentrationPM10=getPM(DUST_SENSOR_DIGITAL_PIN_PM10); Serial.print("PM10: "); Serial.println(concentrationPM10); diff --git a/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino b/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino index 0c495f6..f14a1cf 100644 --- a/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino +++ b/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino @@ -51,17 +51,17 @@ #define MAX_WATT 10000 // Max watt value to report. This filetrs outliers. #define CHILD_ID 1 // Id of the sensor child -unsigned long SEND_FREQUENCY = +uint32_t SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway. double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour bool pcReceived = false; -volatile unsigned long pulseCount = 0; -volatile unsigned long lastBlink = 0; -volatile unsigned long watt = 0; -unsigned long oldPulseCount = 0; -unsigned long oldWatt = 0; +volatile uint32_t pulseCount = 0; +volatile uint32_t lastBlink = 0; +volatile uint32_t watt = 0; +uint32_t oldPulseCount = 0; +uint32_t oldWatt = 0; double oldKwh; -unsigned long lastSend; +uint32_t lastSend; MyMessage wattMsg(CHILD_ID,V_WATT); MyMessage kwhMsg(CHILD_ID,V_KWH); MyMessage pcMsg(CHILD_ID,V_VAR1); @@ -91,7 +91,7 @@ void presentation() void loop() { - unsigned long now = millis(); + uint32_t now = millis(); // Only send values at a maximum frequency or woken up from sleep bool sendTime = now - lastSend > SEND_FREQUENCY; if (pcReceived && (SLEEP_MODE || sendTime)) { @@ -99,7 +99,7 @@ void loop() if (!SLEEP_MODE && watt != oldWatt) { // Check that we dont get unresonable large watt value. // could hapen when long wraps or false interrupt triggered - if (watt<((unsigned long)MAX_WATT)) { + if (watt<((uint32_t)MAX_WATT)) { send(wattMsg.set(watt)); // Send watt value to gw } Serial.print("Watt:"); @@ -142,8 +142,8 @@ void receive(const MyMessage &message) void onPulse() { if (!SLEEP_MODE) { - unsigned long newBlink = micros(); - unsigned long interval = newBlink-lastBlink; + uint32_t newBlink = micros(); + uint32_t interval = newBlink-lastBlink; if (interval<10000L) { // Sometimes we get interrupt on RISING return; } @@ -151,7 +151,4 @@ void onPulse() lastBlink = newBlink; } pulseCount++; -} - - - +} \ No newline at end of file diff --git a/examples/LightSensor/LightSensor.ino b/examples/LightSensor/LightSensor.ino index e249e2c..505bc8c 100644 --- a/examples/LightSensor/LightSensor.ino +++ b/examples/LightSensor/LightSensor.ino @@ -40,7 +40,7 @@ #define CHILD_ID_LIGHT 0 #define LIGHT_SENSOR_ANALOG_PIN 0 -unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) +uint32_t SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; diff --git a/examples/MockMySensors/MockMySensors.ino b/examples/MockMySensors/MockMySensors.ino index de375b5..158deff 100644 --- a/examples/MockMySensors/MockMySensors.ino +++ b/examples/MockMySensors/MockMySensors.ino @@ -86,7 +86,7 @@ // Global Vars -unsigned long SLEEP_TIME = 900000; // Sleep time between reads (in milliseconds) +uint32_t SLEEP_TIME = 900000; // Sleep time between reads (in milliseconds) bool metric = true; long randNumber; @@ -721,7 +721,7 @@ void loop() } // This is called when a new time value was received -void receiveTime(unsigned long controllerTime) +void receiveTime(uint32_t controllerTime) { Serial.print("Time value received: "); diff --git a/examples/MotionSensor/MotionSensor.ino b/examples/MotionSensor/MotionSensor.ino index 0deb09e..bc1133a 100644 --- a/examples/MotionSensor/MotionSensor.ino +++ b/examples/MotionSensor/MotionSensor.ino @@ -38,7 +38,7 @@ #include -unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds) +uint32_t SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds) #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define CHILD_ID 1 // Id of the sensor child diff --git a/examples/MotionSensorRS485/MotionSensorRS485.ino b/examples/MotionSensorRS485/MotionSensorRS485.ino index 5518bff..a1713fa 100644 --- a/examples/MotionSensorRS485/MotionSensorRS485.ino +++ b/examples/MotionSensorRS485/MotionSensorRS485.ino @@ -62,7 +62,7 @@ #include -unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds) +uint32_t SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds) #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define CHILD_ID 1 // Id of the sensor child diff --git a/examples/PHSensor/PHSensor.ino b/examples/PHSensor/PHSensor.ino index ce86255..1a9cb30 100644 --- a/examples/PHSensor/PHSensor.ino +++ b/examples/PHSensor/PHSensor.ino @@ -35,7 +35,7 @@ #define COMPARE_PH 1 // Send PH only if changed? 1 = Yes 0 = No -unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds) +uint32_t SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds) float lastPH; bool receivedConfig = false; bool metric = true; diff --git a/examples/SecurityPersonalizer/SecurityPersonalizer.ino b/examples/SecurityPersonalizer/SecurityPersonalizer.ino index 0939786..882d523 100644 --- a/examples/SecurityPersonalizer/SecurityPersonalizer.ino +++ b/examples/SecurityPersonalizer/SecurityPersonalizer.ino @@ -432,8 +432,8 @@ static const uint8_t reset_buffer[32] = { void setup() { // Delay startup a bit for serial consoles to catch up - unsigned long enter = hwMillis(); - while (hwMillis() - enter < (unsigned long)500); + uint32_t enter = hwMillis(); + while (hwMillis() - enter < (uint32_t)500); #ifdef USE_SOFT_SIGNING // initialize pseudo-RNG hwRandomNumberInit(); @@ -530,8 +530,8 @@ static bool generate_random_data(uint8_t* data, size_t sz) #if defined(USE_SOFT_SIGNING) && ! defined(MY_HW_HAS_GETENTROPY) for (size_t i = 0; i < sz; i++) { data[i] = random(256) ^ micros(); - unsigned long enter = hwMillis(); - while (hwMillis() - enter < (unsigned long)2); + uint32_t enter = hwMillis(); + while (hwMillis() - enter < (uint32_t)2); } return true; #elif defined(USE_SOFT_SIGNING) && defined(MY_HW_HAS_GETENTROPY) diff --git a/examples/SoilMoistSensor/SoilMoistSensor.ino b/examples/SoilMoistSensor/SoilMoistSensor.ino index f8a9c86..bc76be3 100644 --- a/examples/SoilMoistSensor/SoilMoistSensor.ino +++ b/examples/SoilMoistSensor/SoilMoistSensor.ino @@ -77,7 +77,7 @@ #define CHILD_ID 0 MyMessage msg(CHILD_ID, V_LEVEL); -unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) +uint32_t SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) long buffer[NUM_READS]; int idx; diff --git a/examples/UVSensor/UVSensor.ino b/examples/UVSensor/UVSensor.ino index 0dc5a76..c024621 100644 --- a/examples/UVSensor/UVSensor.ino +++ b/examples/UVSensor/UVSensor.ino @@ -51,11 +51,11 @@ #define CHILD_ID_UV 0 -unsigned long SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds) +uint32_t SLEEP_TIME = 30*1000; // Sleep time between reads (in milliseconds) MyMessage uvMsg(CHILD_ID_UV, V_UV); -unsigned long lastSend =0; +uint32_t lastSend =0; float uvIndex; float lastUV = -1; uint16_t uvIndexValue [12] = { 50, 227, 318, 408, 503, 606, 696, 795, 881, 976, 1079, 1170}; @@ -72,7 +72,7 @@ void presentation() void loop() { - unsigned long currentTime = millis(); + uint32_t currentTime = millis(); uint16_t uv = analogRead(UV_SENSOR_ANALOG_PIN);// Get UV value if (uv>1170) { diff --git a/examples/VibrationSensor/VibrationSensor.ino b/examples/VibrationSensor/VibrationSensor.ino index 2ebe342..d28c6d5 100644 --- a/examples/VibrationSensor/VibrationSensor.ino +++ b/examples/VibrationSensor/VibrationSensor.ino @@ -48,7 +48,7 @@ #define VIBRATION_SENSOR_DIGITAL_PIN 3 #define SensorLED 13 -unsigned long SLEEP_TIME = 10*1000; // Sleep time between reads (in seconds) +uint32_t SLEEP_TIME = 10*1000; // Sleep time between reads (in seconds) //VARIABLES int val = 0; // variable to store the value coming from the sensor diff --git a/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino b/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino index 36c0605..3f70756 100644 --- a/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino +++ b/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino @@ -55,7 +55,7 @@ #define CHILD_ID 1 // Id of the sensor child -unsigned long SEND_FREQUENCY = +uint32_t SEND_FREQUENCY = 30000; // Minimum time between send (in milliseconds). We don't want to spam the gateway. MyMessage flowMsg(CHILD_ID,V_FLOW); @@ -64,17 +64,17 @@ MyMessage lastCounterMsg(CHILD_ID,V_VAR1); double ppl = ((double)PULSE_FACTOR)/1000; // Pulses per liter -volatile unsigned long pulseCount = 0; -volatile unsigned long lastBlink = 0; +volatile uint32_t pulseCount = 0; +volatile uint32_t lastBlink = 0; volatile double flow = 0; bool pcReceived = false; -unsigned long oldPulseCount = 0; -unsigned long newBlink = 0; +uint32_t oldPulseCount = 0; +uint32_t newBlink = 0; double oldflow = 0; double volume =0; double oldvolume =0; -unsigned long lastSend =0; -unsigned long lastPulse =0; +uint32_t lastSend =0; +uint32_t lastPulse =0; void setup() { @@ -102,7 +102,7 @@ void presentation() void loop() { - unsigned long currentTime = millis(); + uint32_t currentTime = millis(); // Only send values at a maximum frequency or woken up from sleep if (SLEEP_MODE || (currentTime - lastSend > SEND_FREQUENCY)) { @@ -122,7 +122,7 @@ void loop() // Check that we dont get unresonable large flow value. // could hapen when long wraps or false interrupt triggered - if (flow<((unsigned long)MAX_FLOW)) { + if (flow<((uint32_t)MAX_FLOW)) { send(flowMsg.set(flow, 2)); // Send flow value to gw } } @@ -160,7 +160,7 @@ void loop() void receive(const MyMessage &message) { if (message.type==V_VAR1) { - unsigned long gwPulseCount=message.getULong(); + uint32_t gwPulseCount=message.getULong(); pulseCount += gwPulseCount; flow=oldflow=0; Serial.print("Received last pulse count from gw:"); @@ -172,8 +172,8 @@ void receive(const MyMessage &message) void onPulse() { if (!SLEEP_MODE) { - unsigned long newBlink = micros(); - unsigned long interval = newBlink-lastBlink; + uint32_t newBlink = micros(); + uint32_t interval = newBlink-lastBlink; if (interval!=0) { lastPulse = millis();