LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 11-24-2019, 10:13 AM   #1
CollieJim
Member
 
Registered: Mar 2005
Distribution: Gentoo, Kubuntu
Posts: 582

Rep: Reputation: 28
HC-06 resends last message on connection loss


The remote controls for my TV and Satellite box are failing, so I made a new remote that uses Bluetooth rather than IR.

The keypad uses an STM32C103C8T6 (Blue Pill) and an HC-05, and sends the 4-byte code. The receiver uses an Arduino Pro Mini and HC-06, and feeds it to the irremote library.

It works quite well, but has a rather annoying behavior when the keypad is turned off to save its battery.

20 seconds after the keypad is turned off, the receiver's HC-06 starts blinking rapidly indicating it's waiting for a connection. At that time it appears to send to the Pro Mini the last message again, followed by 2 messages containing a single 'c'. If the last command was to turn off the TV, it gets turned on again!

The workaround is to make sure the last button pressed does nothing.
Do I have a weird module, or am I missing something?
Perhaps the extra messages are part of the protocol to indicate connection loss?


Code:
#define  Tx_Pin   6
#define  Rx_Pin   5

#include <SoftwareSerial.h>
SoftwareSerial mySerial ( Rx_Pin, Tx_Pin ); // RX, TX

#include <IRremote.h>             // IR remote control library
IRsend irsend;

// pin for the LED:
const int IR_Pin = 3;
const int FB_Pin = 8;

#define NEC   1                   // tell library to use NEC protocol
char dbg[20];
char buf[20];     // receives code from BT link
int  i;
unsigned long key;
/*
 *  Visual feedback
 */
void Blink ( int Count )
{
    for ( int j = 0; j < Count; j++ )
    {
        digitalWrite ( FB_Pin, HIGH );
        delay ( 100 );
        digitalWrite ( FB_Pin, LOW );
        delay ( 100 );
    }
}

void Blink1 ( )
{
    digitalWrite ( FB_Pin, HIGH );
    delay ( 20 );
    digitalWrite ( FB_Pin, LOW );
}
/*
 *   Get code to send via IR as ASCII HEX
 *     and return binary value in key
 */
void GetCode ( void )
{
    for ( i = 0; i < 20; i++ )
        buf[i] = 0;
    
    while ( !mySerial.available ( ) );   // wait for something

    i = 0;
    do
    {
        while ( !mySerial.available ( ) );   // wait for something
        buf[i] = mySerial.read ( );
        i++;
    } while ( buf[i-1] >= '0');

    // get rid of any trailing stuff
    if ( mySerial.available ( ) )
        mySerial.read ( );
    delay ( 2 );    
    if ( mySerial.available ( ) )
        mySerial.read ( );
    delay ( 2 );    
    if ( mySerial.available ( ) )
        mySerial.read ( );

    sscanf ( buf, "%lX", &key );
    Serial.println ( key, HEX );
}

void setup ( )
{
    Serial.begin ( 38400 );
    mySerial.begin ( 38400 );
    
//  pinMode ( IR_Pin, OUTPUT );
    pinMode ( FB_Pin, OUTPUT );
    Blink ( 8 );
    Serial.println ( "Starting" );
}

void loop ( )
{
    GetCode ( );                    // blocking
    irsend.sendNEC ( key, 32 );
    Blink1 ( );
}
 
Old 11-24-2019, 10:38 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,832

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you might need to clean the variable key too (after irsend)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Loss Of Network Connection After Power Loss etpoole60 Linux - Virtualization and Cloud 2 10-27-2014 03:14 PM
TCP resends and behaves as if there was no loss?!? dhavey Linux - Kernel 2 07-17-2012 11:49 AM
evolution resends prior day email upon reboot rholme Linux - General 6 11-07-2009 06:39 AM
Network Connection Loss And USB Connection Loss. Novatian Linux - Desktop 1 11-07-2008 02:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 01:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration