Skip to content

Commit

Permalink
Handling Devices with Firmware >= 5.8 but no humidity and pressure se…
Browse files Browse the repository at this point in the history
…nsor (indilib#628)
  • Loading branch information
pmneo authored Aug 12, 2022
1 parent 35eb24a commit 1994703
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 50 deletions.
8 changes: 8 additions & 0 deletions debian/indi-aagcloudwatcher-ng/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
indi-aagcloudwatcher-ng (1.7) focal; urgency=medium

* Added Debug Output
* Handling Devices with Firmware >= 5.8 but no humidity and pressure sensor
* Fixed Sensor Tab Mapping

-- Philip Mair <[email protected]> Sun, 7 August 2022 12:00:00 +0200

indi-aagcloudwatcher-ng (1.6) focal; urgency=medium

* Add support for humidity and pressure sensors.
Expand Down
2 changes: 1 addition & 1 deletion indi-aagcloudwatcher-ng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules/")
include(GNUInstallDirs)

set (AAG_VERSION_MAJOR 1)
set (AAG_VERSION_MINOR 6)
set (AAG_VERSION_MINOR 7)

find_package(INDI REQUIRED)
find_package(Threads REQUIRED)
Expand Down
40 changes: 34 additions & 6 deletions indi-aagcloudwatcher-ng/CloudWatcherController_ng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,34 +143,38 @@ bool CloudWatcherController::getAllData(CloudWatcherData *cwd)

if (!check)
{
LOG_ERROR( "ERROR in getIRSkyTemperature" );
return false;
}

check = getIRSensorTemperature(&sensorTemperature[i]);

if (!check)
{
LOG_ERROR( "ERROR in getIRSensorTemperature" );
return false;
}

check = getRainFrequency(&rainFrequency[i]);

if (!check)
{
LOG_ERROR( "ERROR in getIRSensorTemperature" );
return false;
}

check = getValues(&internalSupplyVoltage[i], &ambientTemperature[i], &ldrValue[i], &rainSensorTemperature[i]);

if (!check)
{
LOG_ERROR( "ERROR in getValues" );
return false;
}

check = getWindSpeed(&windSpeed[i]);

if (!check)
{
LOG_ERROR( "ERROR in getWindSpeed" );
return false;
}

Expand All @@ -180,6 +184,7 @@ bool CloudWatcherController::getAllData(CloudWatcherData *cwd)

if (!check)
{
LOG_ERROR( "ERROR in getHumidity" );
return false;
}
}
Expand All @@ -191,6 +196,7 @@ bool CloudWatcherController::getAllData(CloudWatcherData *cwd)

if (!check)
{
LOG_ERROR( "ERROR in getPressure" );
return false;
}
}
Expand Down Expand Up @@ -225,6 +231,7 @@ bool CloudWatcherController::getAllData(CloudWatcherData *cwd)

if (!check)
{
LOG_DEBUG( "ERROR in getIRErrors" );
return false;
}

Expand All @@ -234,13 +241,15 @@ bool CloudWatcherController::getAllData(CloudWatcherData *cwd)

if (!check)
{
LOG_DEBUG( "ERROR in getPWMDutyCycle" );
return false;
}

check = getSwitchStatus(&cwd->switchStatus);

if (!check)
{
LOG_DEBUG( "ERROR in getSwitchStatus" );
return false;
}

Expand Down Expand Up @@ -466,7 +475,6 @@ bool CloudWatcherController::getIRSensorTemperature(int *temp)
}

int res = sscanf(inputBuffer, "!2 %d", temp);

if (res != 1)
{
return false;
Expand Down Expand Up @@ -672,7 +680,12 @@ bool CloudWatcherController::getHumidity(int *humidity)
if (h == 100)
return false;

*humidity = h * 125 / 65536 - 6;
if( h == 65535 ) {
*humidity = 0;
}
else {
*humidity = h * 125 / 65536 - 6;
}

return true;
}
Expand All @@ -699,13 +712,19 @@ bool CloudWatcherController::getPressure(int *pressure)

if (!r)
{
return false;
*pressure = 0;
return true;
}

int p = 0;
int res = sscanf(inputBuffer, "!p %d", &p);

*pressure = p / 16;
if( p == 65535 ) {
*pressure = 0;
}
else {
*pressure = p / 16;
}

if (res != 1)
{
Expand Down Expand Up @@ -904,6 +923,8 @@ bool CloudWatcherController::sendCloudwatcherCommand(const char *command, int si
int n = 0;
char errstr[MAXRBUF];

LOGF_DEBUG( "sendCloudwatcherCommand(%s,%i)", command, size );

if ((rc = tty_write(PortFD, command, size, &n)) != TTY_OK)
{
tty_error_msg(rc, errstr, MAXRBUF);
Expand Down Expand Up @@ -932,8 +953,15 @@ bool CloudWatcherController::getCloudWatcherAnswer(char *buffer, int nBlocks)
return false;
}

if( buffer[0] == '!' && ( buffer[1] == 'f' || buffer[1] == 'd' ) ) {
LOGF_DEBUG( "skip answer %s %i", buffer, nBlocks );
return getCloudWatcherAnswer(buffer, nBlocks);
}

int valid = checkValidMessage(buffer, nBlocks);

LOGF_DEBUG( "getCloudWatcherAnswer(%s,%i) = %s", buffer, nBlocks, valid ? "valid" : "invalid" );

if (!valid)
{
return false;
Expand Down Expand Up @@ -962,4 +990,4 @@ void CloudWatcherController::printBuffer(char *buffer, int num)
{
std::cout << buffer[i];
}
}
}
7 changes: 6 additions & 1 deletion indi-aagcloudwatcher-ng/README.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AAG Cloud Watcher INDI Driver v1.3
AAG Cloud Watcher INDI Driver v1.7

A INDI driver for the AAG Cloud Watcher (AAGware - http://www.aagware.eu/)

Expand All @@ -7,6 +7,11 @@ A INDI driver for the AAG Cloud Watcher (AAGware - http://www.aagware.eu/)

Anemometer code contributed by Joao Bento.

Version 1.7

+ Added Debug Output
+ Handling Devices with Firmware >= 5.8 but no humidity and pressure sensor
+ Fixed Sensor Tab Mapping

Version 1.3

Expand Down
64 changes: 35 additions & 29 deletions indi-aagcloudwatcher-ng/indi_aagcloudwatcher_ng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,20 +592,20 @@ bool AAGCloudWatcher::sendData()
return false;

INumberVectorProperty *nvp = getNumber("readings");
nvp->np[SENSOR_SUPPLY].value = data.supply;
nvp->np[SENSOR_SKY].value = data.sky;
nvp->np[SENSOR_SENSOR].value = data.sensor;
nvp->np[SENSOR_AMBIENT].value = data.ambient;
nvp->np[SENSOR_RAIN].value = data.rain;
nvp->np[SENSOR_RAIN_HEATER].value = data.rainHeater;
nvp->np[SENSOR_RAIN_TEMPERATURE].value = data.rainTemperature;
nvp->np[SENSOR_LDR].value = data.ldr;
nvp->np[SENSOR_READ_CYCLES].value = data.readCycle;
nvp->np[RAW_SENSOR_SUPPLY].value = data.supply;
nvp->np[RAW_SENSOR_SKY].value = data.sky;
nvp->np[RAW_SENSOR_SENSOR].value = data.sensor;
nvp->np[RAW_SENSOR_AMBIENT].value = data.ambient;
nvp->np[RAW_SENSOR_RAIN].value = data.rain;
nvp->np[RAW_SENSOR_RAIN_HEATER].value = data.rainHeater;
nvp->np[RAW_SENSOR_RAIN_TEMPERATURE].value = data.rainTemperature;
nvp->np[RAW_SENSOR_LDR].value = data.ldr;
nvp->np[RAW_SENSOR_READ_CYCLES].value = data.readCycle;
lastReadPeriod = data.readCycle;
nvp->np[SENSOR_WIND_SPEED].value = data.windSpeed;
nvp->np[SENSOR_RELATIVE_HUMIDITY].value = data.humidity;
nvp->np[SENSOR_PRESSURE].value = data.pressure;
nvp->np[SENSOR_TOTAL_READINGS].value = data.totalReadings;
nvp->np[RAW_SENSOR_WIND_SPEED].value = data.windSpeed;
nvp->np[RAW_SENSOR_RELATIVE_HUMIDITY].value = data.humidity;
nvp->np[RAW_SENSOR_PRESSURE].value = data.pressure;
nvp->np[RAW_SENSOR_TOTAL_READINGS].value = data.totalReadings;
nvp->s = IPS_OK;
IDSetNumber(nvp, nullptr);

Expand All @@ -621,9 +621,10 @@ bool AAGCloudWatcher::sendData()
INumberVectorProperty *nvpS = getNumber("sensors");

float skyTemperature = float(data.sky) / 100.0;
nvpS->np[0].value = skyTemperature;
nvpS->np[1].value = float(data.sensor) / 100.0;
nvpS->np[2].value = data.rain;
nvpS->np[SENSOR_INFRARED_SKY].value = skyTemperature;
nvpS->np[SENSOR_INFRARED_SENSOR].value = float(data.sensor) / 100.0;

nvpS->np[SENSOR_RAIN_SENSOR].value = data.rain;

float rainSensorTemperature = data.rainTemperature;
if (rainSensorTemperature > 1022)
Expand All @@ -639,11 +640,11 @@ bool AAGCloudWatcher::sendData()
rainSensorTemperature =
1.0 / (rainSensorTemperature / constants.rainBetaFactor + 1.0 / (ABS_ZERO + 25.0)) - ABS_ZERO;

nvpS->np[3].value = rainSensorTemperature;
nvpS->np[SENSOR_RAIN_SENSOR_TEMPERATURE].value = rainSensorTemperature;

float rainSensorHeater = data.rainHeater;
rainSensorHeater = 100.0 * rainSensorHeater / 1023.0;
nvpS->np[4].value = rainSensorHeater;
nvpS->np[SENSOR_RAIN_SENSOR_HEATER].value = rainSensorHeater;

float ambientLight = float(data.ldr);
if (ambientLight > 1022.0)
Expand All @@ -655,7 +656,7 @@ bool AAGCloudWatcher::sendData()
ambientLight = 1.0;
}
ambientLight = constants.ldrPullUpResistance / ((1023.0 / ambientLight) - 1.0);
nvpS->np[5].value = ambientLight;
nvpS->np[SENSOR_BRIGHTNESS_SENSOR].value = ambientLight;

setParameterValue("WEATHER_BRIGHTNESS", ambientLight);

Expand All @@ -681,7 +682,7 @@ bool AAGCloudWatcher::sendData()
1.0 / (ambientTemperature / constants.ambientBetaFactor + 1.0 / (ABS_ZERO + 25.0)) - ABS_ZERO;
}

nvpS->np[6].value = ambientTemperature;
nvpS->np[SENSOR_AMBIENT_TEMPERATURE_SENSOR].value = ambientTemperature;

INumberVectorProperty *nvpSky = getNumber("skyCorrection");
float k1 = getNumberValueFromVector(nvpSky, "k1");
Expand All @@ -694,10 +695,10 @@ bool AAGCloudWatcher::sendData()
skyTemperature - ((k1 / 100.0) * (ambientTemperature - k2 / 10.0) +
(k3 / 100.0) * pow(exp(k4 / 1000 * ambientTemperature), (k5 / 100.0)));

nvpS->np[7].value = correctedTemperature;
nvpS->np[8].value = data.windSpeed;
nvpS->np[9].value = data.humidity;
nvpS->np[10].value = data.pressure;
nvpS->np[SENSOR_CORRECTED_INFRARED_SKY].value = correctedTemperature;
nvpS->np[SENSOR_WIND_SPEED].value = data.windSpeed;
nvpS->np[SENSOR_HUMIDITY].value = data.humidity;
nvpS->np[SENSOR_PRESSURE].value = data.pressure;
nvpS->s = IPS_OK;
IDSetNumber(nvpS, nullptr);

Expand Down Expand Up @@ -817,7 +818,7 @@ bool AAGCloudWatcher::resetData()
nvpE->s = IPS_IDLE;
IDSetNumber(nvpE, nullptr);

const int N_SENS = 9;
const int N_SENS = 10;
double valuesS[N_SENS];
char *namesS[N_SENS];

Expand All @@ -838,16 +839,21 @@ bool AAGCloudWatcher::resetData()

namesS[5] = const_cast<char *>("brightnessSensor");
valuesS[5] = 0.0;

setParameterValue("WEATHER_BRIGHTNESS", 0);

namesS[6] = const_cast<char *>("ambientTemperatureSensor");
namesS[6] = const_cast<char *>("correctedInfraredSky");
valuesS[6] = 0.0;

namesS[7] = const_cast<char *>("correctedInfraredSky");
namesS[7] = const_cast<char *>("ambientTemperatureSensor");
valuesS[7] = 0.0;

namesS[6] = const_cast<char *>("windSpeed");
valuesS[6] = 0.0;
namesS[8] = const_cast<char *>("windSpeed");
valuesS[8] = 0.0;

namesS[9] = const_cast<char *>("pressure");
valuesS[9] = 0.0;

setParameterValue("WEATHER_WIND_SPEED", 0);

INumberVectorProperty *nvpS = getNumber("sensors");
Expand Down
41 changes: 28 additions & 13 deletions indi-aagcloudwatcher-ng/indi_aagcloudwatcher_ng.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,34 @@ class AAGCloudWatcher : public INDI::Weather

enum
{
SENSOR_SUPPLY,
SENSOR_SKY,
SENSOR_SENSOR,
SENSOR_AMBIENT,
SENSOR_RAIN,
SENSOR_RAIN_HEATER,
SENSOR_RAIN_TEMPERATURE,
SENSOR_LDR,
SENSOR_READ_CYCLES,
SENSOR_WIND_SPEED,
SENSOR_RELATIVE_HUMIDITY,
SENSOR_PRESSURE,
SENSOR_TOTAL_READINGS
RAW_SENSOR_SUPPLY,
RAW_SENSOR_SKY,
RAW_SENSOR_SENSOR,
RAW_SENSOR_AMBIENT,
RAW_SENSOR_RAIN,
RAW_SENSOR_RAIN_HEATER,
RAW_SENSOR_RAIN_TEMPERATURE,
RAW_SENSOR_LDR,
RAW_SENSOR_READ_CYCLES,
RAW_SENSOR_WIND_SPEED,
RAW_SENSOR_RELATIVE_HUMIDITY,
RAW_SENSOR_PRESSURE,
RAW_SENSOR_TOTAL_READINGS
};

enum
{
SENSOR_INFRARED_SKY, //skyTemperature
SENSOR_CORRECTED_INFRARED_SKY, //correctedTemperature
SENSOR_INFRARED_SENSOR,
SENSOR_RAIN_SENSOR, //data.sensor
SENSOR_RAIN_SENSOR_TEMPERATURE, //rainSensorTemperature
SENSOR_RAIN_SENSOR_HEATER, //rainSensorHeater
SENSOR_BRIGHTNESS_SENSOR, //ambientLight
SENSOR_AMBIENT_TEMPERATURE_SENSOR, //ambientTemperature
SENSOR_WIND_SPEED, //data.windSpeed;
SENSOR_HUMIDITY, //data.humidity;
SENSOR_PRESSURE //data.pressure;
};

};

0 comments on commit 1994703

Please sign in to comment.