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

Rework of the itho packet section, cleanup and easier to understand, improved stability #11

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

arjenhiemstra
Copy link

Complete rework of the itho packet section, cleanup and easier to understand, improved stability

*  Library structure is preserved, should be a drop in replacement (apart from device id)
*  Decode incoming messages to direct usable decimals without further bit-shifting
*  DeviceID is now 3 bytes long and can be set during runtime
*  Counter2 is now the decimal sum of all bytes in decoded form from deviceType up to the last byte before counter2 subtracted from zero.
*  Encode outgoing messages in itho compatible format
*  Added ICACHE_RAM_ATTR to 'void ITHOcheck()' for ESP8266/ESP32 compatibility
*  Trigger on the falling edge and simplified ISR routine for more robust packet handling
*  Move SYNC word from 171,170 further down the message to 179,42,163,42 to filter out more non-itho messages in CC1101 hardware
   Tested on ESP8266 & ESP32

…erstand

   Library structure is preserved, should be a drop in replacement (apart from device id)
   Decode incoming messages to direct usable decimals without further bit-shifting
   DeviceID is now 3 bytes long and can be set during runtime
   Counter2 is the decimal sum of all bytes in decoded form from deviceType up to the last byte before counter2 subtracted from zero.
   Encode outgoing messages in itho compatible format
   Added ICACHE_RAM_ATTR to 'void ITHOcheck()' for ESP8266/ESP32 compatibility
   Trigger on the falling edge and simplified ISR routine for more robust packet handling
   Move SYNC word from 171,170 further down the message to 179,42,163,42 to filter out more non-itho messages in CC1101 hardware

   Tested on ESP8266 & ESP32
Implemented basic incoming message validity check
reverted to 16 bits but a few byes further down the message than the original lib
The even bits are always the inverse of the odd bits, use this principle to improve stability of the itho command check
Clean up some of the logging code
fix: Change arduino.h to Arduino.h
fix: change typo 0, 5 to 0.5
feat: Add support to receive and monitor itho RF-RFT and RF-RV remotes.
feat: Add possibility to join devices (by join command or manually) to the lib and keep track of commands and values (co2, humidity, temp, battery)

New lib functions:

Manually add devices to the known devices list by ID:
bool addRFDevice(uint8_t byte0, uint8_t byte1, uint8_t byte2);
bool addRFDevice(uint32_t ID);

Manually remove devices to the known devices list by ID:
bool removeRFDevice(uint8_t byte0, uint8_t byte1, uint8_t byte2);
bool removeRFDevice(uint32_t ID);

Check is device is known by ID:
bool checkRFDevice(uint8_t byte0, uint8_t byte1, uint8_t byte2);
bool checkRFDevice(uint32_t ID);

Allow (true/false) if devices are allowed to join (standard value: true):
void setBindAllowed(bool input);

Get join allowed status:
bool getBindAllowed();

Receive and handle all devices (standard value: true, for backwards compatibility)
void setAllowAll(bool input);

Get allowed all devices status:
bool getAllowAll();

Get reference to struct which contains all remotes and last known data (co2, temp etc.)
const struct ithoRFDevices &getRFdevices() const;

Sample code to walk to data and create a JSON:

```
  DynamicJsonDocument doc(2000);
  JsonObject root = doc.to<JsonObject>();

  const ithoRFDevices &rfDevices = rf.getRFdevices();
  for (auto& item : rfDevices.device) {
	if (item.deviceId != 0) {
	  char buf[10];
	  snprintf(buf, sizeof(buf), "%02X,%02X,%02X", item.deviceId >> 16 & 0xFF, item.deviceId >> 8 & 0xFF, item.deviceId & 0xFF);
	  JsonObject nested = root.createNestedObject(buf);
	  nested["lastcmd"] = item.lastCommand;
	  if (item.co2 != 0xEFFF) {
		nested["co2"] = item.co2;
	  }
	  if (item.temp != 0xEFFF) {
		nested["temp"] = item.temp;
	  }
	  if (item.hum != 0xEFFF) {
		nested["hum"] = item.hum;
	  }
	  if (item.dewpoint != 0xEFFF) {
		nested["dewpoint"] = item.dewpoint;
	  }
	  if (item.battery != 0xEFFF) {
		nested["battery"] = item.battery;
	  }
	}
  }
```

Example resulting JSON:
```
{"E0,58,45":{"lastcmd":4},"52,4E,9A":{"lastcmd":0},"97,95,A1":{"lastcmd":0,"temp":2079,"hum":52,"dewpoint":1062},"97,28,ED":{"lastcmd":0,"co2":1033}}
```
- fix: bugs in example
- fix: initialise buffers to known value
- fix: includes
- fix: command bytes matching to be more specific
- fix: remove sprintf calls and replace them with snprintf
- change: standby command removed and replaced by away command
- feat: add support to receive different RF device types (RFT AUTO, RFT DF/QF, RFT CO2, RFT RV, preliminary Orcon support)
- feat: add command to name logging function
Add RF send support for different types of itho remotes (RFT Auto, RFT DF/QF, RFT CO2, RFT RV, RFT PIR, RFT Auto-N)
use:
rf.updateRFDeviceType(RemoteType, RemoteIndex); //to set remote type
Possible remote types:
  UNSETTYPE
  RFTCVE
  RFTAUTO
  RFTAUTON
  DEMANDFLOW
  RFTRV
  RFTCO2
  RFTPIR
  ORCON15LF01

RFT AutoN currently only supported in legacy mode
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

Successfully merging this pull request may close these issues.

1 participant