joergkeller / beehive-sensor

Temperature and humidity measurement in a beehive using Arduino and LoRaWan (TTN).
MIT License
13 stars 7 forks source link

Problem with RGB OFF #9

Open emilvi opened 3 years ago

emilvi commented 3 years ago

When I set up RGB OFF it stops with "-> Enter state Measure". My setup is Cube Cell, HX711, DHT22, no One-wire I have tried to set "#define THERMOMETER_COUNT 5" to "0", but then the compilation fails With RGB ON it works OK. (but then the battery drains fast...)

I'm waiting for the resistor for DHT22, this is not set up, but it seems that the one-wire is measured first and causing the problem

07:36:32.194 -> MLME Confirmation: STATUS_OK 07:36:32.194 -> Joined! 07:36:32.194 -> Exit state Join 07:36:32.194 -> 07:36:32.194 -> Enter state Measure ----- Here is stops with RGB OFF ----- 07:36:33.741 -> Thermometer 0 @ 0x28C2E1780A000026 shows -127.00 C 07:36:33.741 -> -5.76 kg 07:36:33.741 -> 18.00 C roof 07:36:33.741 -> 43.70 % rel roof 07:36:33.741 -> 3.86 Vbat 07:36:33.741 -> Exit state Measure 07:36:33.741 -> 07:36:33.741 -> Enter state Transmit

BR Emil Visdal

joergkeller commented 3 years ago

Hi Emil I've tried to reproduce that problem. With no one-wire thermometer there could be a problem with temperature-compensation of the scale. The logic reads the one-wire thermometer 0 anyway, then checks for the special case of -127.00 C in SensorReader.h. You could try to comment-out that attempt completely:

[SensorReader.h, line 132ff]
    float getCompensatedWeight() {
      if (!scaleIsReady) { return -127.0f; }
      float weight = getWeight();
//      float outerTemperature = sensors.getTempC(thermometer[THERMOMETER_OUTER]);
//      if (isnan(outerTemperature) || outerTemperature == -127.0f) {
        return weight;
//      } else {
//        return weight - (TEMPERATURE_FACTOR * outerTemperature) - TEMPERATURE_OFFSET;
//      }
    }

To "#define THERMOMETER_COUNT 0", you should comment-out the initialization part as well.

[calibration.h, your relevant device settings]
  #define THERMOMETER_COUNT 0 // number of 1-wire thermometers, addresses below
  #define THERMOMETER_OUTER 0 // 0-based index of temperature reading for weight compensation
  const DeviceAddress thermometer[THERMOMETER_COUNT] = {
//    { 0x28, 0xC2, 0xE1, 0x78, 0x0A, 0x00, 0x00, 0x26 }, // 0: Aussentemperatur
//    { 0x28, 0x3F, 0x1C, 0x31, 0x02, 0x00, 0x00, 0x02 }, // 1: Temperatur Kälteloch
//    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 2: Temperatur 200mm
//    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // 3: Temperatur 300mm
//    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }  // 4: Temperatur 400mm
  };

I have no HX711 scale for testing at hand, so I faked the weight and got the following output:

Copyright @ 2019 Heltec Automation.All rights reserved.
Scale not ready
Start 'cube-cell-1' beehive LoRa script with sensor message v0 (9 bytes)

Enter state Join                                                                
Device joining: "00000000256A11B5"                                              
Joining OTAA...                                                                 
MLME Confirmation: STATUS_OK                                                    
Joined!                                                                         
Exit state Join                                                                 

Enter state Measure
2.56 kg
3.92 Vbat
Exit state Measure

Enter state Transmit
Message: "008801000100800080"
Sending uplink packet
MCPS Confirmation: STATUS_OK
Datarate: 2
TxPower: 0
Retries: 0
AckReceived: 0
Counter: 0
Exit state Transmit

Enter state Sleep                                                               
296 s sleeping                

My compile settings (same results with RGB=1):

arduino-cli compile -u -p /dev/ttyUSB0 --fqbn=CubeCell:CubeCell:CubeCell-Board:LORAWAN_REGION=5,LORAWAN_CLASS=0,LORAWAN_NETMODE=0,LORAWAN_ADR=1,LORAWAN_UPLINKMODE=1,LORAWAN_Net_Reserve=0,LORAWAN_AT_SUPPORT=1,LORAWAN_RGB=0,LORAWAN_DebugLevel=0 arduino_beehive_sensor_lora/arduino_beehive_sensor_lora.ino

Important! I'm still working with version 1.1.0 of the CubeCell core. There seems to be a problem running my code with the latest 1.2.0:

arduino-cli core list
ID                Installed Latest Name                          
CubeCell:CubeCell 1.1.0     1.2.0  CubeCell Development Framework
joergkeller commented 3 years ago

It works with the latest CubeCell core 1.2.0 if you change compile settings (Region 6=REGION_EU868):

arduino-cli compile -u -p /dev/ttyUSB0 --fqbn=CubeCell:CubeCell:CubeCell-Board:LORAWAN_REGION=6,LORAWAN_CLASS=0,LORAWAN_DEVEUI=0,LORAWAN_NETMODE=0,LORAWAN_ADR=1,LORAWAN_UPLINKMODE=1,LORAWAN_Net_Reserve=0,LORAWAN_AT_SUPPORT=0,LORAWAN_RGB=0,LORAWAN_DebugLevel=0 arduino_beehive_sensor_lora/arduino_beehive_sensor_lora.ino
joergkeller commented 3 years ago

@emilvi, do you still have the problem with that branch or is the disabled temperature compensation the solution?

emilvi commented 3 years ago

Still the same problem, have tried latest fixes. But I have tried to put the scale reading latest, the measure is done, but there is probably other settings that has to be done. I belive that this has to do with the fact that the HX711 need time between samplings. I have been working with another project and after that what i can remember it needs 2 sec between samplings, also when trying to read from channel B. I have ordered DS18B20 but it will take some time before I get it.

` for (int m = 0; m < 2; m++) { message[m].sensor.version = MESSAGE_VERSION; message[m].sensor.battery = UNDEFINED_VALUE; message[m].sensor.humidity.roof = UNDEFINED_VALUE; message[m].sensor.temperature.roof = UNDEFINED_VALUE;

if THERMOMETER_COUNT > 0

for (int i = 0; i < THERMOMETER_COUNT; i++) {
  message[m].sensor.temperature.other[i] = UNDEFINED_VALUE;
message[m].sensor.weight = UNDEFINED_VALUE;
}

void readSensors(byte index) { sensor.startReading(); message[index].sensor.battery = asShort(sensor.getVoltage()); message[index].sensor.humidity.roof = asShort(sensor.getRoofHumidity()); message[index].sensor.temperature.roof = asShort(sensor.getRoofTemperature());

if THERMOMETER_COUNT > 0

for (int i = 0; i < THERMOMETER_COUNT; i++) { message[index].sensor.temperature.other[i] = asShort(sensor.getTemperature(i)); } message[index].sensor.weight = asShort(sensor.getCompensatedWeight());

endif

sensor.stopReading(); }

void printSensorData(byte index) {

if THERMOMETER_COUNT > 0

for (int i = 0; i < THERMOMETER_COUNT; i++) { print(message[index].sensor.temperature.other[i], String(" C level ") + i); }

endif

print(message[index].sensor.temperature.roof, " C roof"); print(message[index].sensor.humidity.roof, " % rel roof"); print(message[index].sensor.battery, " Vbat"); print(message[index].sensor.weight, " kg"); } `

22:29:17.456 -> Enter state Measure 22:29:18.249 -> 3.27 Vbat 22:29:18.282 -> 0.00 kg 22:29:18.282 -> 1808s since transmission 22:29:18.282 -> Exit state Measure

As you see that the scale is 0.00 and Temp and Humidity from DHT22 is not working

joergkeller commented 3 years ago

Hi @emilvi, I'm back from skiing vacation, now I want to solve that problem, it's still strange that I can't reproduce it. I have prepared some stripped-down versions and would be grateful if you could try them out (in the reverse order I've created them).

1) A dummy version that does not really read any sensor other than the voltage. DHT22 should be 20.1 celsius and 79% humidity, weight 23.45 kg. If you rename the credentials template and set your OTAA keys, it should transmit those values. beehive-sensor-dummy-sensor-3.zip

Capture

2) Read DHT22 and HX711 scale, but no other temperature sensors. And yes, when initializing I do wait for the scale to become ready. And I only read again after 5 minutes. This should work even if you don't have a HX711 and DHT22 at hand. I'm interested in your results with and without these sensors. beehive-sensor-no-onewire-2.zip

3) Normal code but number of temperature sensors is set to 0. And I've removed all macros that I use to handle multiple devices with different credentials and calibrations. beehive-sensor-single-device-1.zip

I have tried all three versions with a CubeCell without any sensors attached. Could you give me a feedback on how they perform in your setup?

emilvi commented 3 years ago

I have tried all. Number 3 gives the dummy result and worked with RGB OFF Number 2 and 1 stops on "Enter Measure State" both with no devices attached and with DHT22 and HX711 attached Number 2 and 1 works with RGB ON BTW: I'm running on a windows 10 machine with Arduino CC SW with latest version

emilvi commented 3 years ago

I now have tested on a different computer, and installed all from scratch, with the same result. But I have discovered that there probably is 2 different versions of HTCC-AB01. I have the version on this page https://resource.heltec.cn/download/CubeCell/HTCC-AB01/HTCC-AB01_PinoutDiagram.pdf. The difference is GPIO4 and GPIO5 have changed places. Have tried to compile with GPIO5 (without changing the pin), but with same result

joergkeller commented 3 years ago

Regarding GPIO4/5, I think they had a problem with an old PDF for the Pinout diagram. My board also matches the linked diagram. Anyway, you should be safe when you plug/solder the sensors according to the labels on the board.

Does not explain however why Number 2 and 1 do not work with no devices attached ;-)

I've developed originaly also on Win 10 with the Arduino IDE, but have moved now to a virtual Fedora 33 instance with Arduino CLI. And you also have CubeCell 1.2.0 installed?

emilvi commented 3 years ago

I have tested all the versions of Cubecell up to version 1.2.0 with same result Maybe I could have connected wrong so I have put in my cabling here, I also have a battery connected to battery contact on the other side scale

joergkeller commented 3 years ago

Hi Emil What confused me most, is the tests number 2/1 with no sensor attached, since this is exactly what I do test on my side and certainly can not be a wiring mistake. So I removed and reinstalled the Arduino IDE on Win10 and made test 2 again. Two findings:

1) It is documented but I never explicitly asked (because in the CLI I don't have to care about it): Did you set the Sketchbook location in the preferences to the project repository (instead of %user%\Arduino)? This is not the default, but ensures that Arduino will use the libraries defined in the github project instead of any libraries globally loaded on your computer. That could explain different behaviours. image

2) I found a problem in my code about state handling. State 'sleep' has a timeout, additionally there is a timer that should also end the sleep mode. I have to test in other configurations, but in the below additional test 2a) I've made a quick fix. Could you test that again without any sensors (and with DHT22 and HX711, if you like). beehive-sensor-no-onewire-2a.zip

emilvi commented 3 years ago

I have checked the Sketchbook location and that is correct. I also use Cubecell v 1.2.0 I have testet v 2a with

emilvi commented 3 years ago

I think i figured it out now. found this https://github.com/bogde/HX711/pull/193/commits/8115aee8766a388edaec5b46735df82ba7ae5935 I changed ...\libraries\HX711\src\HX711.cpp from pinMode(DOUT, INPUT_PULLUP); to pinMode(DOUT, INPUT); And it worked right away. I will test some more