Hans-Beerman / CompressorNodeSoftware-main

Main *.ccp code of CompressorNodeSoftware

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Source code CompressorNode Makerspace Leiden

Current version: V0.12 Concept

This repository contains the source code for the CompressorNode used in the Makerspace Leiden.

This CompressorNode is based on the use of the Olimex ESP32_PoE. This small processor board is plugged on a backplane, details about this backplane can be found here:

https://github.com/Hans-Beerman/CompressorNode

This software is developed with Visual Studio Code in combination with the extension PlatformIO.

This CompressorNode (the hardware in combination with the software) has the following features:

  • Button On: to manual switch on the compressor;
  • Button Off: to manual switch off the compressor;
  • Button On + Button Off: if both buttons are pressed together for more than 5 seconds, while calibration mode is disabled, calibration mode will be disabled. Pressing both buttons together while calibration mode is enabled, calibration mode is disabled immediately. Also the duratution counters are saved in flash, every time calibration mode is enabled;
  • but1: also used to toggle info / calibration mode on or off. but1 is the second button of the ESP32-PoE module. Press this button, when the node is running (the boot screen is not shown anymore). When info calibration mode is active each second e.g. the IP address and calibration info is logged to MQTT and telnet etc. Also the duratution counters are saved in flash, every time this button is pressed;
  • Automatic switch on: switch the compressor on by means of dedicated MQTT messages
  • Automatic switch off: switch the compressor off by means of dedicated MQTT mesages
  • Timeout: the compressor will automatically switch off after a certain (in source code) configured timeout, currently after 30 minutes. Pressing Button On again (or sending MQTT command), while the compressor is switched on, will extend the timeout with 30 minutes;
  • Late hour disable: after a configured time in the evening (currently 22:00 h) and before a configured time in the morning (currently 08:00 h) the compressor is disabled to prevent too much noise for our neighbors. This means the compressor will not start automatically by means of MQTT messages. Also the compressor will not start if the Button On is pressed normally;
  • Overrule late hour disable: the late hour disable function can be overruled by pressing the Button On continuously for more than 10 seconds;
  • 230VAC relais output: to switch the compressor on or off;
  • 230VAC opto coupler input: This input is connected to one of the phases of the 3-phase motor of the compressor to detect if the motor is running or not;
  • 2 LED's: for signaling purposes. LED1 is on continuously when the compressor is switched on. LED2 is on continuously when the motor in the compressor is switched on. LED1 will flash for 5 s with 200 ms intervals if Button On is pressed during late hour disable. Both LED's will flash simultaneously with 600 ms intervals if there is an error which make it impossible to operate the compressor. The LED's will flash until the error is solved. The following two errors will disable de compressor:
    • Oil level too low;
    • Temperature to high;
  • Measurement of the machine temperature: the temperature of the compressor is measured and reported via MQTT. The temperature is also shown on the display of the node. There are 2 temperature sensors, one is measuring the temperture of the motor, the other measures the temperature of the compressor;
  • Measurement of the oil level: The oil level of the compressor is measured and reported via MQTT. This pressure is also shown on the display of the node;
  • Measurement of air pressure: The air pressure, as produced by the compressor is measured and reported via MQTT. This pressure is also shown on the display of the node;
  • Status show on display: There is a small Oled display (128x128 pixels) which shows status information about the node and the compressor.

Setup of the software development environment

See https://github.com/dirkx/AccesSystem/tree/master/lib-arduino/ACNode for an introduction of how the software development environment can be setup. The description here however is based on the use of the Arduino software development tool. It will give you information about the libraries needed to compile the source code of the compressor node.

In addition to this description the following libraries are needed:

  • NTP: NTP by Stefan Staub (#include <NTP.h>;) current version 1.4.

For more information about this library see:

https://platformio.org/lib/show/5438/NTP

This library is used to collect the correct local time via NTP;

  • DallasTemperature: DallasTemperature by Miles Burton (#include <DallasTemperature.h>), current version 3.6.1, this library is used for the one wire temperature sensor based on the DS18B20;
  • U8x8lib: U8g2 library by oliver (#include <U8x8lib.h>), current version 2.28.2, this library is used for the 128x128 pixels Oled display used.

WARNING: In PubSubClient.h the following define must be changed from 256 to 340: #define MQTT_MAX_PACKET_SIZE 340

Configuratie PlatformIO

The configuration for this Project in PlatformIO is stored in the platformio.ini file, the content of this file is shown next, the IP address (192.168.5.95) is the current IP address of the node in the Makerspace, please change this to the correct IP address, given by the network to which the node is connected:

;PlatformIO Project Configuration File

;

; Build options: build flags, source filter

; Upload options: custom upload port, speed and extra flags

; Library options: dependencies, extra library storages

; Advanced options: extra scripting

;

; Please visit documentation for the other options and examples

; https://docs.platformio.org/page/projectconf.html

[env:esp32-poe]

platform = espressif32

board = esp32-poe

framework = arduino

; enable ota

upload_protocol = espota

upload_port = 192.168.5.95

upload_flags =

--port=8266

--auth=MyPassWoord

; evaluate C/C++ Preprocessor conditional syntax

lib_ldf_mode = deep+

;upload_port = /dev/ttyUSB0

monitor_speed = 115200

board_build.partitions = huge_app.csv

Configuration of the behaviour of the Node

With the following parameters in the source code the behaviour of the node can be controlled:

  • Temperature limits:

In main.cpp:

// temperature sensor

#define TEMP_SENSOR_LABEL1 ("Compressor") // label used in logging for temp. sensor 1

#define TEMP_SENSOR_LABEL2 ("Motor") // label used in logging for temp. sensor 2

#define TEMP_REPORT_ERROR1 ("temperature_sensor_1_(compressor)_error") // label used in reporting for temp. sensor 1

#define TEMP_REPORT_WARNING1 ("temperature_sensor_1_(compressor)_warning") // label used in reporting for temp. sensor 1

#define TEMP_REPORT\1 ("temperature_sensor_1_(compressor)") // label used in reporting for temp. sensor 1

#define TEMP_REPORT_ERROR2 ("temperature_sensor_2_(motor)_error") // label used in reporting for temp. sensor 2

#define TEMP_REPORT_WARNING2 ("temperature_sensor_2_(motor)_warning") // label used in reporting for temp. sensor 2

#define TEMP_REPORT2 ("temperature_sensor_2_(motor)") // label used in reporting for temp. sensor 2

#define TEMP_IS_HIGH_LEVEL_1 (60.0) // in degrees Celcius, used for temperature is high warning of sensor 1

#define TEMP_IS_TOO_HIGH_LEVEL_1 (90.0) // in degrees Celcius, used to disable the compressor when temperature is too high of sensor 1

#define TEMP_IS_HIGH_LEVEL_2 (60.0) // in degrees Celcius, used for temperature is high warning of sensor 2

#define TEMP_IS_TOO_HIGH_LEVEL_2 (90.0) // in degrees Celcius, used to disable the compressor when temperature is too high of sensor 2

  • Pressure limits, used for safety: In main.cpp:

#define PRESSURE_MAX_LIMIT (12.0) // Compressor must be switched off above this limit for safety #define PRESSURE_BELOW_LIMIT (10.0) // If compressor was switched off because pressure was to high, // compressor can be switched on again if pressure becomes below this limit

  • The LED's dim value: In main.cpp:

#define LED1_DIM_VALUE (50) // 0 - 255, 0 = LED1 is off #define LED2_DIM_VALUE (50) // 0 - 255, 0 = LED2 is off

  • The time interval of the LED's in case of an error:

In main.cpp:

// For LED's showing node error

#define BLINKING_LED_PERIOD (600) // in ms

  • The time window between saves of the duration counters:

In main.cpp:

// for storage in EEProm of the duration counters

#define SAVE_DURATION_COUNTERS_WINDOW (86400) // in seconds (86400 = 24 hour)

  • For the automatic timeout of the compressor:

In main.cpp:

// for auto switch off of the compressor

#define AUTOTIMEOUT (30 * 60 * 1000) // default: in ms 30 * 60 * 1000 = 30 minutes

  • For the late hour disable function:

In main.cpp:

// Compressor disabled (or not) at late hours:

// IF the compressor is not allowed at late hours (DISABLE_COMPRESSOR AT LATE HOURS = true) the

// compressor will not switch on automatically (or by hand if the on button is pressed normally) from

// DISABLED_TIME_START to DISABLED_START_END

// Pressing the on button longer than MAX_WAIT_TIME_BUTTON_ON_PRESSED will override this behaviour by

// switching on the compressor anyhow. In all cases the compressor will switch of after AUTOTIMEOUT (in ms)

// unless the button on is pressed again or a new auto on command is received while the compressor is

// already switched on. In both cases the time will be extended by AUTOTIMEOUT ms.

#define DISABLE_COMPRESSOR_AT_LATE_HOURS (true)

#define DISABLED_TIME_START (19) // in hour, time from which the compressor is not automatically switched on

#define DISABLED_TIME_END (8) // in hour, time to which the compressor is not automatically switched on

#define MAX_WAIT_TIME_BUTTON_ON_PRESSED (10000) // in ms, time button on must be pressed to override late hour compressor disable

#define LED_DISABLE_DURATION (5000) // in ms, the time LED1 will flash if button on is pressed during late hour

#define LED_DISABLE_PERIOD (200) // in ms, the time LED1 will flash on/off

  • Time window for calibration buttons

In main.cpp:

#define CALIB_WINDOW_TIME (5000) // in ms

  • Clear EEProm and cache, by pressing but1 of the ESP32-PoE module during boot for some time:

In main.cpp:

#define MAX_WAIT_TIME_BUTTON_PRESSED (4000) // in ms

  • For logging to MQTT etc.:

In main.cpp:

#define LOGGING_ENABLED (true) // to enable/disable logging

#define LOGGING_TIME_\WINDOW (20000) // in ms

  • The time between updates of the display:

In OledDisplay.cpp:

// oled display

#define DISPLAY_WINDOW (1000) // in ms, update display time

  • The time short status messages are shown on the bottom line of the display:

In OledDisplay.cpp

#define KEEP_STATUS_LINE_TIME (5000) // in ms, default = 5 s (5000), the time certain status messages are shown on the bottom line of the display

  • The time the oil level is too low, before an error is signaled:

In OilLevelSensor.cpp:

#define MAX_OIL_LEVEL_IS_TOO_LOW_WINDOW (10000) // in ms default 10000 = 10 seconds. Error is signalled after this time window is passed

  • For calibration of the air pressure sensor:

See the following parameters:

  • Pressure calibrating values:

In PressureSensor.cpp:

#define PRESSURE_CALIBRATE_VALUE_0_5V (144) // in measured bits

#define PRESSURE_CALIBRATE_VALUE_4_5V (2600) // in measured bits

The air pressure sensor output is 0.5 V when the pressure is 0 bar.

The output is 4.5 V when the pressure is 12 bar

  • The time between samples of the air pressure:

In PressureSensor.cpp:

#define PRESSURE_SAMPLE_WINDOW (1000) // in ms

  • The time the temperature is too high, before an error is signaled:

In TempSensor.cpp:

#define MAX_TEMP_IS_TOO_HIGH_WINDOW (10000) // in ms default 10000 = 10 seconds. Error is only signalled after this time window is passed

About

Main *.ccp code of CompressorNodeSoftware

License:Apache License 2.0


Languages

Language:C++ 98.6%Language:C 1.4%