Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BTHR968 #14

Open
platone58 opened this issue Dec 28, 2020 · 13 comments
Open

BTHR968 #14

platone58 opened this issue Dec 28, 2020 · 13 comments

Comments

@platone58
Copy link

hello, I lost my BTHR968 of the WMR968 station, I tried to simulate with your program and it doesn't work or at least it works only t temperature and humidity as part in one of the three channels but only as a THGN132 sensor, I tried with other programs found on the net but yours is the only one who calculates something right in the two nibbles after the post-amble, or so I'm convinced.
can you help me?

@invandy
Copy link
Owner

invandy commented Jan 25, 2021

Hello. Ofcorse it is possiible to simulate your lost sensor with "Transmitter"and if you need a real data - with "BME280_Transmiter" examples. You have to change packet length, data fields and method of calculating CRC8. Moreover validiry of pressure data in you sensor packet is still doubtfull and requre additional researching with real sensor. I have no one.

@platone58
Copy link
Author

platone58 commented Jan 25, 2021 via email

@invandy
Copy link
Owner

invandy commented Jan 26, 2021

ОК. Lets try to make BTHR emulator with common efforts. First, I'll make a sketch that will send a test packets, and you will test one on your weather station and give me a table with two columns:

  1. sent pressure data
  2. weather station pressure readings
    Also you'll have to pick up with your weather station the transmission intervals that is suitable for this sensor
    Second, we will create a final sketch.
    Do you plan to make a emulator only or device with battery and timer, like in "BME280_Transmiter" example?

@platone58
Copy link
Author

platone58 commented Jan 26, 2021 via email

@invandy
Copy link
Owner

invandy commented Jan 26, 2021

#include <Oregon_TM.h>

//variables is to be find out

#define SEND_TIME 40000; //from datasheet - "around 40 seconds"
#define CRC_START_SUM 0x00 //I suppose this value is 0x00, but not shure

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
unsigned long time_marker_send = 0;
Oregon_TM transmitter(4, 28);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(115200);
transmitter.buffer_size = 23;
transmitter.protocol = 2;

transmitter.setType(0x5D60);
transmitter.SendBuffer[2] &= 0x0F; //no channel data
transmitter.setId(0xF0); //suitable values for for this sensor: A7h, F0h

transmitter.SendBuffer[3] = 0;
transmitter.setBatteryFlag(0); // Full battery
transmitter.setTemperature(20.4); // +20.4
transmitter.setHumidity(40); // 40%
transmitter.setComfort(20.4, 40); //

//Set pressure data
word pressure_data = 0x19D; //0x19D, 0x186 and so on
transmitter.SendBuffer[7] &= 0xF0;
transmitter.SendBuffer[7] += pressure_data & 0x0F;
transmitter.SendBuffer[8] = ((pressure_data & 0xF00) >> 8) + (pressure_data & 0xF0);

//Set forecast
transmitter.SendBuffer[9] = 0x60;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
if (millis() >= time_marker_send)
{
calculateAndSetChecksum();
transmitter.SendPacket();
time_marker_send = millis() + SEND_TIME;
PrintSentData(transmitter.SendBuffer);
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void PrintSentData(byte* buf)
{
Serial.print(millis() / 1000);
Serial.print("s \t\t");
for (byte i = 0; i < transmitter.buffer_size; i++)
{
byte trmbuf = *buf;
Serial.print(trmbuf >> 4, HEX);
i++;
if (i >= transmitter.buffer_size) break;
Serial.print(trmbuf & 0x0F, HEX);
buf++;
}
Serial.println();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void calculateAndSetChecksum()
{
byte CCIT_POLY = 0x07;
transmitter.SendBuffer[9] = transmitter.SendBuffer[9] & 0xF0;
transmitter.SendBuffer[10] = 0x00;
transmitter.SendBuffer[11] = 0x00;
byte summ = 0x00;
byte crc = CRC_START_SUM;
byte cur_nible;
for(int i = 0; i < 10; i++)
{
cur_nible = (transmitter.SendBuffer[i] & 0xF0) >> 4;
summ += cur_nible;
if (i != 3)
{
crc ^= cur_nible;
for(int j = 0; j < 4; j++)
if (crc & 0x80) crc = (crc << 1) ^ CCIT_POLY;
else crc <<= 1;
}
cur_nible = transmitter.SendBuffer[i] & 0x0F;
summ += cur_nible;
if (i != 2)
{
crc ^= cur_nible;
for(int j = 0; j < 4; j++)
if (crc & 0x80) crc = (crc << 1) ^ CCIT_POLY;
else crc <<= 1;
}
}
transmitter.SendBuffer[9] += summ & 0x0F;
transmitter.SendBuffer[10] += summ & 0xF0;
transmitter.SendBuffer[10] += crc & 0x0F;
transmitter.SendBuffer[11] += crc & 0xF0;
}

@invandy
Copy link
Owner

invandy commented Jan 26, 2021

Try this.
First, Put your weather station into search mode and try to send packets with CRC_START_SUM = 0. If it will be unseccessefull, try other values.
Second, after exiting from search mode station have to keep connection with sensor if SEND_TIME is correct. I found "around 40 seconds" in sensor datasheet, but do not know what they mean exactly

@platone58
Copy link
Author

platone58 commented Jan 26, 2021 via email

@invandy
Copy link
Owner

invandy commented Jan 26, 2021

Try CRC_START_SUM = 0xA1

@invandy
Copy link
Owner

invandy commented Jan 26, 2021

I found real packet from sensor "5D600CE26610840091C3683" and loaded it in "CRC8_search" utility. At CCIT_POLY = 0x07 it gives CRC_START_SUM = 0xA1

@platone58
Copy link
Author

platone58 commented Jan 26, 2021 via email

@invandy
Copy link
Owner

invandy commented Jan 26, 2021

Don't forget about table :)

@platone58
Copy link
Author

platone58 commented Jan 26, 2021 via email

@invandy
Copy link
Owner

invandy commented Jan 26, 2021

After exiting search mode almost all Oregon stations block sensors with incorrect transmission interval. Lost data on the display in 15-20 minutes means that you set a wrong interval. Try to increase e.g. temperature on 0.1C with every transmisson. If data stops change on the display it means that connection is lost.
Try pressure_data = 0x19D, 0x186 and 0x190 at least and write a displayed pressure value. It will allow to correct calculate pressure field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants