Skip to content

Commit

Permalink
at least two protocols successfully decoded; experimented with differ…
Browse files Browse the repository at this point in the history
…ent rcswitch versions; updated readme
  • Loading branch information
mightymos committed Nov 20, 2023
1 parent 2ee414e commit d7b846d
Show file tree
Hide file tree
Showing 11 changed files with 776 additions and 45 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
# Besides make, his project requires:
#
# - sdcc
# - stcgal-patched
# - minicom
# - doxygen


# Usage ----------------------------------------------------------------
#
Expand Down Expand Up @@ -65,7 +63,6 @@ MCU_FREQ_KHZ := 16000
MEMORY_SIZES = \
--iram-size 256 \
--xram-size 256 \
# --stack-size $(STACK_SIZE) \
--code-size 8192

#
Expand Down
56 changes: 41 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,65 @@
# Introduction

This is an alternative firmware for radio decoding implemented on an 8052 based On-Bright OB38S003 microcontroller.
This microcontroller is present in the Sonoff Bridge R2 v2.2 433 MHz radio receiver.
This is an alternative firmware for radio protocol decoding.
The firmware targets an 8052 based On-Bright OB38S003 microcontroller.
This microcontroller is present in the Sonoff Bridge R2 v2.2 433 MHz radio to wifi bridge.
The intent is to avoid the need to perform hardware modification while still allowing support for additional radio protocols.

The firmware is inspired by 1) RF-Bridge-EFM8BB1 (Portisch) and 2) rc-switch projects.

Description of Sonoff R2 v2.2 bridge hardware modification is here:
https://github.com/arendst/Tasmota/discussions/13283

# Status
THIS IS A WORK IN PROGRESS and should not be used by typical users (yet).
Please note that HELP is needed (see Flasher sections below).

That said, decoding of "protocol 1" seems to work reliably.
That said, decoding of protocols 1 and 2 seems to work reliably.
For example door reed sensors - both stock and modified - have been successfully decoded.
https://github.com/mightymos/ReedTripRadio
https://github.com/mightymos/ReedTripRadio

| Feature | detail | status |
| ------------- | ------------- | ------------- |
| Protocol testing | we need some scheme to evaluate reliability | TODO |
| Sniffing | allow viewing timing of unknown radio protocols | TODO |
| Transmission | operate as remote control | TODO |
| Port to R2 v1.0 bridge (black box) | makefile may be toughest portion | TODO |

# Installation
Install SDCC compiler for your platform:
https://sdcc.sourceforge.net/

On command line run make.
Built firmware placed in build directory.
See flasher section below (requires msm9066 flasher for now).

Transmission also works - however, strange things happen when both transmission and receiving are enabled.
Therefore transmitting is disabled for now.
# Previous Work

An attempt was made to compile portisch with the open source SDCC compiler.
8KB code space appeared to be exceeded.
I personally found the source code to be difficult to read.
https://github.com/mightymos/SonOfPortisch

There are at least three versions of rcswitch.
We attempt to use the simplest and most understandable for now (from sui77).
https://github.com/sui77/rc-switch
https://github.com/1technophile/rc-switch
https://github.com/arendst/Tasmota/tree/development/lib/lib_rf/rc-switch

# Hardware Modification (avoids need for this project)
Description of Sonoff R2 v2.2 bridge hardware modification is here:
https://github.com/arendst/Tasmota/discussions/13283

# Flasher
Reprogramming the OB38S003 requires erasing the chip because the stock firmware is protected.
This means that, once erased, the stock firmware cannot be recovered because it has not been read out.
A MSM9066 programmer is required presently ($30 USD as of 7/14/2023 on AliExpress).
A MSM9066 programmer is required currently ($30 USD as of 7/14/2023 on AliExpress; $27 on eBay as of 11/20/2023).

# Flasher (alternative)
Logic analyzer decodings of several flasher operations/programming cycles have been captured:
https://github.com/mightymos/msm9066_capture
https://github.com/mightymos/msm9066_capture

Help is needed to create an alternative programmer/flasher:
https://github.com/mightymos/msm9066_capture/issues/1
HELP is needed to create an alternative programmer/flasher:
https://github.com/mightymos/msm9066_capture/issues/1


Use of a cheaper flasher or using Tasmota itself is probably required for widespread use.
Use of a cheaper flasher hardware or using Tasmota itself is probably required for widespread use.


# Special Thanks
Expand Down
File renamed without changes.
118 changes: 118 additions & 0 deletions inc/rcswitch_tasmota.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
RCSwitch - Arduino libary for remote control outlet switches
Copyright (c) 2011 Suat Özgür. All right reserved.
Contributors:
- Andre Koehler / info(at)tomate-online(dot)de
- Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com
- Skineffect / http://forum.ardumote.com/viewtopic.php?f=2&t=46
- Dominik Fischer / dom_fischer(at)web(dot)de
- Frank Oltmanns / <first name>.<last name>(at)gmail(dot)com
- Max Horn / max(at)quendi(dot)de
- Robert ter Vehn / <first name>.<last name>(at)gmail(dot)com
Project home: https://github.com/sui77/rc-switch/
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _RCSwitch_h
#define _RCSwitch_h

#include <stdbool.h>
#include <stdint.h>

// Number of maximum high/Low changes per packet.
// We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync
// Для keeloq нужно увеличить RCSWITCH_MAX_CHANGES до 23+1+66*2+1=157
#define RCSWITCH_MAX_CHANGES 67 // default 67

// separationLimit: minimum microseconds between received codes, closer codes are ignored.
// according to discussion on issue #14 it might be more suitable to set the separation
// limit to the same time as the 'low' part of the sync signal for the current protocol.
// should be set to the minimum value of pulselength * the sync signal
#define RCSWITCH_SEPARATION_LIMIT 4100


bool available(void);
void reset_available(void);

unsigned long long get_received_value(void);
unsigned int get_received_bitlength(void);
unsigned int get_received_delay(void);
unsigned int get_received_protocol(void);
unsigned int* get_received_rawdata(void);
uint8_t get_num_protos(void);

extern bool receive_protocol(const int p, unsigned int changeCount);

/**
* Description of a single pule, which consists of a high signal
* whose duration is "high" times the base pulse length, followed
* by a low signal lasting "low" times the base pulse length.
* Thus, the pulse overall lasts (high+low)*pulseLength
*/
struct HighLow {
uint8_t high;
uint8_t low;
};

/**
* A "protocol" describes how zero and one bits are encoded into high/low
* pulses.
*/
struct Protocol {
/** base pulse length in microseconds, e.g. 350 */
uint16_t pulseLength;
uint8_t PreambleFactor;
struct HighLow Preamble;
uint8_t HeaderFactor;
struct HighLow Header;

struct HighLow zero;
struct HighLow one;

/**
* If true, interchange high and low logic levels in all transmissions.
*
* By default, RCSwitch assumes that any signals it sends or receives
* can be broken down into pulses which start with a high signal level,
* followed by a a low signal level. This is e.g. the case for the
* popular PT 2260 encoder chip, and thus many switches out there.
*
* But some devices do it the other way around, and start with a low
* signal level, followed by a high signal level, e.g. the HT6P20B. To
* accommodate this, one can set invertedSignal to true, which causes
* RCSwitch to change how it interprets any HighLow struct FOO: It will
* then assume transmissions start with a low signal lasting
* FOO.high*pulseLength microseconds, followed by a high signal lasting
* FOO.low*pulseLength microseconds.
*/
bool invertedSignal;
uint16_t Guard;
};





/*
* timings[0] contains sync timing, followed by a number of bits
*/
extern volatile __xdata unsigned int timings[RCSWITCH_MAX_CHANGES];

// буфер длительностей последних четырех пакетов, [0] - последний
extern volatile __xdata unsigned int buftimings[4];

#endif
2 changes: 1 addition & 1 deletion src/hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


#include "hal.h"
#include "ob38s003.h"
#include "ob38s003_sfr.h"


// pg. 3 of OB38S003 datasheet
Expand Down
17 changes: 9 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,18 +322,18 @@ int main (void)
{

// holdover from when we considered using rtos
const __idata unsigned char* stackStart = (__idata unsigned char*) get_stack_pointer() + 1;
//const __idata unsigned char* stackStart = (__idata unsigned char*) get_stack_pointer() + 1;

// FIXME: other protocols are not working
const uint8_t repeats = 8;
const uint8_t protocolId = 1;
//const uint8_t repeats = 8;
//const uint8_t protocolId = 1;

// track elapsed time for doing something periodically (e.g., every 10 seconds)
unsigned long previousTimeSendRadio = 0;
unsigned long previousTimeHeartbeat = 0;
unsigned long elapsedTimeSendRadio;
unsigned long elapsedTimeHeartbeat;
unsigned long heartbeat = 0;
//unsigned long previousTimeSendRadio = 0;
//unsigned long previousTimeHeartbeat = 0;
//unsigned long elapsedTimeSendRadio;
//unsigned long elapsedTimeHeartbeat;
//unsigned long heartbeat = 0;


// upper eight bits hold error or no data flags
Expand Down Expand Up @@ -467,6 +467,7 @@ int main (void)
//enable_global_interrupts();

// DEBUG: using software uart
// FIXME: a little dangerous as-is because basically sits in a while() loop ?
putc('b');
putc('0');
putc('x');
Expand Down
5 changes: 1 addition & 4 deletions src/rcswitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
#include "rcswitch.h"
#include "timer.h"

// we are basically following the same decoding approach used by the rc-switch project
// https://github.com/sui77/rc-switch
// https://github.com/1technophile/rc-switch

// FIXME: explain constants
volatile __xdata struct RC_SWITCH_T gRCSwitch = {0, 0, 0, 0, 60, 4300};
Expand Down Expand Up @@ -129,7 +126,7 @@ bool receive_protocol(const int p, unsigned int changeCount)
return false;
}
}

// ignore very short transmissions: no device sends them, so this must be noise
if (changeCount > 7)
{
Expand Down
Loading

0 comments on commit d7b846d

Please sign in to comment.