Author Topic: Remote temp. transmitter - which sensor is this?  (Read 14287 times)

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Remote temp. transmitter - which sensor is this?
« Reply #15 on: March 05, 2019, 07:27:24 AM »
Any idea how to replicate that kind of signal with Moteino(RF69HW)?
I've done it where I didn't need to keep switching back and forth between OOK and Moteino network.  If you only want the OOK function, I can see what I have.  The code may be too 'married' to another type of device, but the OOK transmitter might be useful. I used Kobuki's code as a base (https://lowpowerlab.com/forum/moteino/new-ook-library-for-moteino/)

Lukapple

  • Full Member
  • ***
  • Posts: 202
Re: Remote temp. transmitter - which sensor is this?
« Reply #16 on: March 05, 2019, 07:30:52 AM »
It would be great, if you can share the OOK function. Thanks!

RoSchmi

  • NewMember
  • *
  • Posts: 23
  • Country: de
Re: Remote temp. transmitter - which sensor is this?
« Reply #17 on: March 06, 2019, 05:35:56 AM »
Hello Lukapple,
I had a look on my code how to retrieve the temperatur in Celsius and Fahrenheit from the received bit stream.
So there is no need to reinvent the wheel.
The code is in C#.

// retrieve the measured temperature as an int from the received '0' and '1' in the char array 'outArray'
Code: [Select]
int gotValue = 0;
int shiftValue = 1;
for (int i = 0 ; i < valueEndPos - valueStartPos + 1; i++ )
{
      if (outArray[valueEndPos - i] == '1')
      {
              gotValue += (shiftValue << i);
      }
      else
      {
             if (outArray[valueEndPos - i] != '0')
             {
                   gotValue = 9999;                  // gotValue = 9999 if there is at least one ? in the array
                   break;
             }
       }
}

// Some calculations to transform the measured values which are valid for
// the range from -50°C to +70°C in a form that can be easily displayed
// I'm sure there are more elegant methods to do this task

//Here the int e.measuredValue holds the temperature (gotValue) from the code above

Code: [Select]
                int measuredValue = e.measuredValue / 2;   // remove last digit, then one bit = 0.1 degree Celcius

                measuredValue = measuredValue & 4095;      // new remove leading 1 s
                //if ((3595 < measuredValue) && (measuredValue < 4096))  // Negative readings are valid from -0.1 to -50 degree Celsius
                if ((3700 < measuredValue) && (measuredValue < 4096))  // Negative readings are valid from -0.1 to -39 degree Celsius

                {
                    measuredValue = 4096 - measuredValue;
                    degreeCelsiusString = "-";
                    degreeCelsiusSign = false;     // sign is "-"
                    measuredValuePlus50 = 500 - measuredValue; // // to have only positive values we add 50 degree Celsius
                }                                                 // then -50°C = 0, 0°C = 50, 70°C = 120
                else                                              // now it is easy to compare with certain thresholds
                {
                    if ((measuredValue >= 0) && (measuredValue < 701)) // Positive readings are valid from 0 to +70 degree Celsius
                    {
                        degreeCelsiusString = "+";
                        degreeCelsiusSign = true;   // sign is "+"
                        measuredValuePlus50 = measuredValue + 500;  // add eqiv. 50 °C
                    }
                    else
                    {
                        degreeCelsiusString = "???";
                    }
                }

                if (degreeCelsiusString != "???")
                {
                    // calculate celsius value
                    //decimalValue = ((double)measuredValue / 10);

                    decimalValue = degreeCelsiusSign ? (double)measuredValue / 10 : -(double)measuredValue / 10;

                    decimalValuePlus50 = ((double)measuredValuePlus50 / 10);  // by adding 50 degree Celsius the valid range -50 - + 70
                    // is now 0 - 120

                    degreeCelsiusString = decimalValue.ToString("f1") + " °C";

                    // calculate fahrenheit from celsius
                    fahrenheitValue = decimalValue * 1.8;
                    if (degreeCelsiusSign == false)
                    { fahrenheitValue = fahrenheitValue * -1; }
                    fahrenheitValue += 32;
                    if (fahrenheitValue >= 0)
                    {
                        degreeFahrenheitString = "+" + fahrenheitValue.ToString("f1") + " °F";
                    }
                    else
                    {
                        degreeFahrenheitString = fahrenheitValue.ToString("f1") + " °F";
                    }
                }
                else
                {
                    decimalValue = InValidValue;
                }

                outString = outString + bitString.Substring(0, 9) + " " + bitString.Substring(9, 15)
                            + " " + bitString.Substring(24, 5) + "  Measured Value: "
                            + degreeCelsiusString + " (+50 = " + decimalValuePlus50.ToString("f1") + ") "
                            + degreeFahrenheitString + "  " + "  Time: "
                            + e.ReadTime.Hour + ":" + e.ReadTime.Minute + ":" + e.ReadTime.Second
                            + "  Repetitions needed: " + e.repCount
                            + "  Failed Bit-Count: " + e.failedBitsCount
                            + "  Eliminated Noise Spikes: " + e.eliminatedSpikesCount;
                _Print_Debug(outString + "\r\n");

Lukapple

  • Full Member
  • ***
  • Posts: 202
Re: Remote temp. transmitter - which sensor is this?
« Reply #18 on: March 06, 2019, 07:03:04 AM »
Actually I already have conversion functions from my other project (temperature sensor DS18B20).  Thanks for the code anyway!

What I really need is example function to reproduce signal with Moteino(RF69HW)? @TomWS can you share a demo sketch please?

Lukapple

  • Full Member
  • ***
  • Posts: 202
Re: Remote temp. transmitter - which sensor is this?
« Reply #19 on: March 07, 2019, 04:59:31 PM »
I've managed to successfully replicate the signal!
Now I can send temperature from my moteino sensors (ch1=outdoor, ch2=pool water temp.) to the wall clock ;D

Thanks for help guys!

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Remote temp. transmitter - which sensor is this?
« Reply #20 on: March 07, 2019, 06:30:23 PM »
Lukapple, that's awesome!
Any chance you can post your code/findings here for posterity?

Lukapple

  • Full Member
  • ***
  • Posts: 202
Re: Remote temp. transmitter - which sensor is this?
« Reply #21 on: March 08, 2019, 02:00:36 AM »
Sure, here is the example sketch, that sends 60.0C signal to channel 1.
It sends following signal 5 times (original temperature transmitter sends package 5x, so I reproduced that):
010101011000100000100101100000010101

Please note that this is just a test sketch and not final production code.  :)
Necessary modifications to the Moteino: connect DIO2 to D3 (INT1) pin (DIO2 is the OOK data pin)



« Last Edit: March 08, 2019, 05:10:10 PM by Lukapple »

RoSchmi

  • NewMember
  • *
  • Posts: 23
  • Country: de
Re: Remote temp. transmitter - which sensor is this?
« Reply #22 on: March 08, 2019, 07:46:57 PM »
Great, thank you.