How To: BrewPi Over Bluetooth

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
Noooooo worries. Wouldn't have gotten this far without your help. (None of us would!)

Alas, things are back to misbehaving at least on the Python side of things. Despite them sitting patiently all afternoon, the second minion is still showing as wanting to be updated. Out of curiosity, I swapped out the arduino with a spare I had - and am still having the same issue. BT board is showing up as paired in Pi, so if it's not the BT, and it's not the Arduino, then can surely only be something on the Pi side that I'm missing. Double checked the /home/brewpi/chamber2/settings/config.cfg file, and can't see an issue. Am somewhat stumped.

Will whack it with a hammer a bit later. Now have to figure out how to stuff these into Hammond 1550WK boxes.
 
Did you program the new arduino over USB? because like I said before, you will never be able to program the arduino over USB. You just program the arduinos first then connect them to the bt dongles.
 
Did you program the new arduino over USB? because like I said before, you will never be able to program the arduino over USB. You just program the arduinos first then connect them to the bt dongles.

Yep, the new one was programmed via USB. Tried via BT, laughed a bit, and then busted out the cable.

But both Arduinos were already programmed, and working fine in a dual setup via USB. The bluetooth.... yeesh. To try and eliminate a variable, I swapped the BT modules between the Arduinos, and now neither of them are showing up in the web interface despite running for a couple of hours at this point. (Both instances showing the "Could not receive version from controller Please (re)program your controller" messages)

The new HC-05s I ordered just showed up... but were just the bare boards without the bluetooth module on them, derpa derp!

So now the current situation is that both HC-05 boards are paired with rfcomm to rfcomm0 and rfcomm1. rfcomm0 works sporadically, haven't gotten any response from rfcomm1. There's another HC-05 on the way, be here next week, and will try that in there.
 
Change the operating baud rate to 57600 1 stop no parity:

Type: 'AT+UART=57600,0,0' and click Send.
Response should be 'OK'

Dumb question of the day.

If the BT modules are supposed to be 57,000 1 stop no parity, shouldn't the command be 'AT+UART=57600,1,0'?

Anyways - pointless ubermick bluetooth update of the day. Received another HC-05, set up the baud rate (hence the question above!) and paired it up as rfcomm2. Changed the settings on chamber2 to read from rfcomm2, and same thing - Could not receive version from controller.

So nuked everything, and started from scratch. And I mean nuked. Full format of the Pi's SD card, reset the HC-05s back to factory default and went through the programming process, uploaded the barebones sketch to the Arduinos in case that had gotten corrupted.

Followed the multi-chamber setup on the Wiki to the letter. Got both Arduinos back up and running with completely new installs under USB. Unplugged the USB cables, paired the HC-05 units with Bluetoothctl, then connected them with rfcomm in the autostart file. Rebooted and...

goddamnit.jpg
 
Just grasping at straws here trying to help out, and this may be a dumb question, could you try to press the reset on the uno and let it reconnect on its own, to see if it's actually connecting or staying connected. it may also be a power issue. what kind of supply voltage are you dealing with?
 
Also could you try using a different browser or try connecting from a Windows machine if you have access to one
 
The 'could not receive version number' issue has popped up before in the big thread. There was a simple fix, either reboot of the Arduino or maybe it was a brewpi update. Your so very close!!! And ya know ya just want to read that thousand page thread again. I'd be popping this in the main thread see if someone remembers the fix.
 
The 'could not receive version number' issue has popped up before in the big thread. There was a simple fix, either reboot of the Arduino or maybe it was a brewpi update. Your so very close!!! And ya know ya just want to read that thousand page thread again. I'd be popping this in the main thread see if someone remembers the fix.
I think that has to do with the CH340 chip- not sure
 
One thought: verify the 1K and 2K resistors for the Uno TX signal level shifter are in the correct positions.
If they were swapped the high signal level would only make it to ~1.6V instead of 3.3...

Cheers!
 
One thought: verify the 1K and 2K resistors for the Uno TX signal level shifter are in the correct positions.
If they were swapped the high signal level would only make it to ~1.6V instead of 3.3...

Cheers!

Also try swapping the leads to the Bluetooth header for RX and TX.
 
OH SON OF A...!

:ban:

I go back and forth on how to label the pins on the header to avoid confusion. Without the shield, I think that most people know you need to connect the TX on the bluetooth module to the RX on the UNO and vice versa. However, when the shield is involved, the natural thought would be that the header pins are labeled so you just hook up the corresponding pins on the bluetooth module and don't worry about the crossover. If I have room on the board I'm working on, I may put a note there to help avoid confusion.

In any case, glad you got it working.
 
I go back and forth on how to label the pins on the header to avoid confusion. Without the shield, I think that most people know you need to connect the TX on the bluetooth module to the RX on the UNO and vice versa. However, when the shield is involved, the natural thought would be that the header pins are labeled so you just hook up the corresponding pins on the bluetooth module and don't worry about the crossover. If I have room on the board I'm working on, I may put a note there to help avoid confusion.

In any case, glad you got it working.


This is why I feel the bt header should line up directly to the pinout of the bt module…
 
Yes, but we established the hc-05's folks in our little group have been using have their RX/TX/5V/GND pins in the same order, so as long as the 4-pin header is positioned to allow an hc-05 to register at both extremes without bumping into anything it should work out...

Cheers!
 
Yes, but we established the hc-05's folks in our little group have been using have their RX/TX/5V/GND pins in the same order, so as long as the 4-pin header is positioned to allow an hc-05 to register at both extremes without bumping into anything it should work out...

Cheers!

Hah. Mine are RX/TX/GND/5V! Personally I don't mind crossing wires around, I had to do it for the relay module as well. What tripped me up is that the LCD shields I got were labeled RX/TX/5V/GND, but seems that RX and TX were reversed on there, and had no reason to think they'd possibly be like that. My own fault in hindsight, as soon as I realized the HC-05s weren't the problem, I should have eliminated the shield in the equation rather than just assuming.

Mind you, don't want to come off as complaining and moaning at Cadi's efforts - the shield is still light years better than my DIY version with the soldered wiring underneath!

618ZyYThBrL._SL1447_.jpg
 
My bad, I wasn't providing an actual sequence, just listing the four pins we care about.
If you go back a couple of weeks in this thread you'll see my hc-05 which has those four pins in the same order, just shifted by a pin...

Cheers!
 
Rather than toss it into the bucket of wonks over on Raspberry Pi forums, thought I'd ask the resident geniuses here...

Just finished my first two minions (squeeeee!) and are running nicely. FINALLY. But if for whatever reason I need to power down one of them, is there a way to have it automatically repair without having to reboot the RPi?
 
I routinely power off my BT minions and they automatically reconnect in a minute or so when powered back up.

I thought you had that working? That was the thing I forgot to mention a few weeks back...

Cheers!
 
I routinely power off my BT minions and they automatically reconnect in a minute or so when powered back up.

I thought you had that working? That was the thing I forgot to mention a few weeks back...

Cheers!

For the most part, I sort of have them working, with the occasional quirk - minion two will randomly report one of the sensors as 185 degrees when I turn it on, and will then gradually drop down to the correct temp. Also, if that one loses bluetooth connection, it'll ocasionally reset itself back to default on reconnect. Bloody weird. (And note the two digit decimal place in the beer temp, which is the one that dropped from 185 degrees.)

But neither will reconnect if I power cycle - I always have to reset the pi in order to get them paired again.

Here's some minion porn (!) tho...

4NoXEzG.jpg
 
How long did you wait, because it isn't instantaneous. the pi will try to start the script for the missing minion until it eventually causes rfcomm to reconnect to the unconnected minion.
 
How long did you wait, because it isn't instantaneous. the pi will try to start the script for the missing minion until it eventually causes rfcomm to reconnect to the unconnected minion.

I've left it overnight without success.

I did revert back to CLI at one point - my wireless on the Pi is horribly spotty when it boots to desktop GUI mode - as soon as the screensaver kicks in for the first time, it can kill it. So I just had it boot to a command line, and set up a script/cron that pings google.com every five minutes, and if it can't find it, to reset the wireless connection. Which worked GREAT, suddenly SSH-ing in is super fast. But think that in bypassing the desktop, I also bypass the startup file which assigns the rfcomm channels.

Went back to the desktop, and sure enough, any minions that are RUNNING are connected on reboot. However if I turn a minion on after this, I get nada. Nosing around, I see that rfcomm files are only being created in the /dev/ folder for those running minions. If they're both on, a reboot on the Pi will see them both running. (Funnily enough, automatically switches their status to "off" as soon as they connect to the Pi)

So am thinking a script of something akin to the checking of wlan0 might work. Check every five minutes to see if rfcomm0 and rfcomm1 are connected, and if not reissue the command?
 
Just to re-iterate, for a reconnect to automatically happen, the BrewPi instance the minion is assigned to must be running a script.

It is the repeated attempts by BrewPi to connect to its assigned device that causes rfcomm to connect; if you stop the script the minion will never reconnect on its own...

Cheers!
 
Nope, script is running in both cases. They're (right now) both set to beer constant, even though they're not connected to anything, and have disabled logging.
 
Could it have something to do with the way the native Bluetooth works on the RPI3 versus what the rest of us do with Bluetooth dongles on older versions?
 
This might work for your script to make sure it reconnects...ignore it if it is way off base.

The problem comes from the python script which does not close the serial port after the Android device has disconnected. One can implement a mechanism (doesn't matter how exactly you want to achieve it) that reacts to a Disconnected message received by rfcomm watch. Namely, when the disconnection occurs, you want to

Either close the port in python by calling Serial.close or kill the python process
Wait for the device to reconnect
Reopen the port or restart the python process
In detail

After calling rfcomm listen <dev> or rfcomm watch <dev>, the Pi is effectively waiting for a connection to be established on /dev/rfcomm0.

When the Android device initiates the connection, the endpoint /dev/rfcomm0 is created and will live forever unless the connection is broken by either of the parties.

In this situation, the python script referred in the question opens up the newly created serial interface (/dev/rfcomm0) via the Serial object abstraction.

Now when the Android device breaks the link, /dev/rfcomm0 is indeed removed but the python Serial object still lives in memory and keeps the port open even though the Android device is down. So when the Android device tries to reconnect after some time, rfcomm watch rightfully complains:

Can't create RFCOMM TTY: Address already in use
simply because the port hasn't been properly closed by the python script when the Android device first left.

To circumvent the problem, one can implement a mechanism (does not matter how exactly you want to achieve it) that reacts to a Disconnected message received by rfcomm watch. Namely, when the disconnection occurs, you want to

Either close the port in python or kill the python process
Wait for the device to reconnect
Reopen the port or restart the python process
 
It's pretty good. I can see mine from inside the fridge nearly 20 feet away
 
Thanks for the great guide - made me a happy chappy for a long time :tank:

I thought I would be even more happy replacing my faithful old RPi model B with a Zero W when it came out... However, so far it's only made me a lot more frustrated :confused:

On the old Model B I used Raspbian Wheezy, but since I have had trouble making it run on the ZW, I decided to switch to Jessie.
My setup is completely headless, so I have to make do with the command line.
Originally I used your instructions in the first post and coupled it with this:
https://www.homebrewtalk.com/showpost.php?p=6624689&postcount=29
After some googling around I discovered that bluez-simple-agent (bluetooth-agent) was discarded, and that I should use bluetoothctl instead.

Long story short - I can't make a rfcomm connection to more than one minion (and I'd really like to get at least two running).

So far my best solution is:
1. Pair/trust both minions using bluetoothctl
2. Create and enable two services: /etc/systemd/system/rfcomm(1+2).service containing:
Code:
[Unit]
Description=RFCOMM service
After=bluetooth.service
Requires=bluetooth.service

[Service]
ExecStart=/usr/bin/rfcomm connect hci0 xx:xx:xx:xx:xx:xx 1

[Install]
WantedBy=multi-user.target

On reboot /dev/rfcomm0 is created, but checking the status of the services reveal the problem:

rfcomm1 (working):
Code:
pi@brewpi:~ $ sudo systemctl status rfcomm1
&#9679; rfcomm1.service - RFCOMM service
   Loaded: loaded (/etc/systemd/system/rfcomm1.service; enabled)
   Active: active (running) since Thu 2017-03-30 15:30:49 CEST; 37min ago
 Main PID: 606 (rfcomm)
   CGroup: /system.slice/rfcomm1.service
           &#9492;&#9472;606 /usr/bin/rfcomm connect hci0 20:16:07:25:12:63 1

Mar 30 15:30:49 brewpi systemd[1]: Started RFCOMM service.
rfcomm2 (dead :( ):
Code:
pi@brewpi:~ $ sudo systemctl status rfcomm2 -l
&#9679; rfcomm2.service - RFCOMM service
   Loaded: loaded (/etc/systemd/system/rfcomm2.service; enabled)
   Active: inactive (dead) since Thu 2017-03-30 15:30:53 CEST; 37min ago
  Process: 604 ExecStart=/usr/bin/rfcomm connect hci0 20:16:07:25:09:80 1 (code=exited, status=0/SUCCESS)
 Main PID: 604 (code=exited, status=0/SUCCESS)

Mar 30 15:30:49 brewpi systemd[1]: Started RFCOMM service.
Mar 30 15:30:53 brewpi rfcomm[604]: Can't create RFCOMM TTY: Address already in use

On my old setup I used /etc/bluetooth/rfcomm.conf to define the rfcomm connections, but it seems it doesn't make a difference anymore.

Any and all suggestions are welcome... (brew day tomorrow so would like to have it running before fermentation...)
 
If you had it all running without a problem on the pi b then why don't you just use the same sd card and put it in the zw. then all you should need to do is update the firmware
 
If you had it all running without a problem on the pi b then why don't you just use the same sd card and put it in the zw. then all you should need to do is update the firmware

Might have to go down that road.... (would of course be considered a defeat by the red guy inside my head)
Last night I decided to start over on a fresh Rapibian Lite image (Jessie).
Installed Brewpi in a multiple chamber setup following this guide (not doing the udev stuff since I won't be using USB anyhow):
http://diybrewpi.wikia.com/wiki/Multiple_Fermentation_Chamber_Control_with_BrewPi

Looking at day_trippr's post (page 36 I think) I added LXDE following this guide:
https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=133691

This time - using Blueman-manager (started from the LXDE menu entry) I was actually able to pair and connect to the minions without any difficulty :D
Following day_trippr's instructions I added the
Code:
sudo rfcomm bind xx:xx:xx:xx:xx:xx 1
for both minions to the lxsession autostart file.

On reboot however, only rfcomm0 is created, and my second minion is still out of reach...
I'm starting to wonder if this could somehow be a limitation on the RPi onboard BT-module?
Read somewhere about someone not being able to stream music to multiple speakers when using the onboard BT, but doing it without hazzle using a dongle...

EDIT:
I decided to give it a shot, updating firmware on my old setup and transferring it to the Zero W.
It boots okay, but the builtin WiFi won't accept the configuration - plugged in a WiFi dongle and it connected to my network.

Both rfcomm devices are created as on the old setup:
Code:
pi@raspberrypi ~ $ ls /dev/rf*
/dev/rfcomm0  /dev/rfcomm1  /dev/rfkill
The BrewPi interface has loaded as expected,although both chambers show "Cannot receive LCD text from Python script" error.
The maintenance panel log shows:
Mar 31 2017 11:26:10 Opening serial port
Mar 31 2017 11:26:20 Errors while opening serial port:
Code:
[Errno 113] could not open port /dev/rfcomm0: [Errno 113] No route to host: '/dev/rfcomm0'
Could not configure port: (25, 'Inappropriate ioctl for device')

dmesg shows bluetootg initializing as I would expect it to:
Code:
pi@raspberrypi ~ $ dmesg | grep Blue
[   38.956871] Bluetooth: Core ver 2.21
[   38.957085] Bluetooth: HCI device and connection manager initialized
[   38.959091] Bluetooth: HCI socket layer initialized
[   38.959131] Bluetooth: L2CAP socket layer initialized
[   38.959227] Bluetooth: SCO socket layer initialized
[   38.998342] Bluetooth: RFCOMM TTY layer initialized
[   38.998392] Bluetooth: RFCOMM socket layer initialized
[   38.998429] Bluetooth: RFCOMM ver 1.11
[   39.016018] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   39.016044] Bluetooth: BNEP filters: protocol multicast
[   39.016086] Bluetooth: BNEP socket layer initialized

Bluetooth appear to be running:
Code:
pi@raspberrypi ~ $ /etc/init.d/bluetooth status
[ ok ] bluetooth is running.

But it appears that the BT device was not loaded:
Code:
pi@raspberrypi ~ $ hciconfig -a
pi@raspberrypi ~ $

EDIT 2 - Follow up on reusing old Wheezy image...
Finally discarded the idea. Tried adding jessie repo to install pi-bluetooth which seems to be essential. No luck installing it, and the whole system became very unstable, loosing connection or crashing every few minutes...

So back to making it run on LXDE on top of Jessie Raspbian Lite
 
Decided to compare the output from hciconfig:
CSR4 on Model B (wheezy)
Code:
pi@raspberrypi ~ $ hciconfig -a
hci0:   Type: BR/EDR  Bus: USB
        BD Address: 00:1A:7D:DA:71:0B  ACL MTU: 310:10  SCO MTU: 64:8
        UP RUNNING
        RX bytes:15380 acl:309 sco:0 events:388 errors:0
        TX bytes:3111 acl:98 sco:0 commands:151 errors:0
        Features: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
        Link policy: RSWITCH HOLD SNIFF PARK
        Link mode: SLAVE ACCEPT
        Name: 'raspberrypi-0'
        Class: 0x420100
        Service Classes: Networking, Telephony
        Device Class: Computer, Uncategorized
        HCI Version: 4.0 (0x6)  Revision: 0x22bb
        LMP Version: 4.0 (0x6)  Subversion: 0x22bb
        Manufacturer: Cambridge Silicon Radio (10)
Onboard module on Zero W (jessie)
Code:
pi@brewpi:~ $ hciconfig -a
hci0:   Type: BR/EDR  Bus: UART
        BD Address: B8:27:EB:9E:57:D7  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING PSCAN
        RX bytes:30262 acl:657 sco:0 events:574 errors:0
        TX bytes:5467 acl:184 sco:0 commands:171 errors:0
        Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
        Link policy: RSWITCH SNIFF
        Link mode: SLAVE ACCEPT
        Name: 'brewpi'
        Class: 0x0c0000
        Service Classes: Rendering, Capturing
        Device Class: Miscellaneous,
        HCI Version: 4.1 (0x7)  Revision: 0xb6
        LMP Version: 4.1 (0x7)  Subversion: 0x2209
        Manufacturer: Broadcom Corporation (15)
Any ideas? Could the UART bus be causing problems? or is it perhaps the missing Link Policies "PARK" and "HOLD" that is somehow missing?
 
Dunno haven't used my pizw yet. just figured that since I had no problem just sticking my pi b sd card into the z 1.0 gave me no issues, figured that since it's the same pi only now with wifi and bt it wouldn't be that hard…. Figures
 
This is just a short post to advise that my DIY RPi/Arduino Brewpi was reconfigured to a BrewPi over Bluetooth setup without any problems following @day_trippr's posts #343 and #352.
Special thanks to @day_trippr and everyone else who has contributed to this thread.
 
[ETA: In order to "Future-Proof" this article, I have created a page for it on the BrewPi Remix website. You can read the most up to date version there.]

I am NOT sure when this changed. @day_trippr is running Wheezy and Jessie and uses the "old" way of setting up a BT device. I'm using Stretch with bluetoothd 5.43 and the method by which you set up /dev/rfcomm* devices with the rfcomm.conf file in /etc/bluetooth is no longer supported. I'm sure someone somewhere could tell me WHY this is better. I'm sure we'd hear some crap about "cloud-enabled" like they tell me with all my favorite Ubuntu items that no longer work.

Anyway, here's how you can get the devices enabled with Stretch. To start with, make sure your HC-05/6 is powered up in its production configuration. At this point it's probably flashing 2-3 times per second. Then, prove to yourself that there's no rfcomm* devices:
Code:
pi@brewpi:~ $ ls -al /dev/rfc*
ls: cannot access '/dev/rfc*': No such file or directory
Next, execute the new CLI for bluez, "bluetoothctl":
Code:
pi@brewpi:~ $ sudo bluetoothctl
[NEW] Controller XX:XX:XX:XX:XX:XX brewpi [default]
The controller listed is your local Pi's controller. After this we need to turn on and configure the "agent" which is the process that allows you to enter the pairing codes when required:
Code:
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful
The next thing to do is allow the system to scan for local devices. If you have a "busy" area bluetooth-wise, you may get a lot of spam. Just let it run about 10 seconds and if you are living a clean life you will see your target BT device and it's MAC address. After that you can turn off the scan.
Code:
[bluetooth]# scan on
Discovery started
[CHG] Controller XX:XX:XX:XX:XX:XX Discovering: yes
[NEW] Device XX:XX:XX:XX:XX:XX XX-XX-XX-XX-XX-XX
[NEW] Device XX:XX:XX:XX:XX:XX [TV] Living room
[NEW] Device XX:XX:XX:XX:XX:XX Chamber 1
[...]
[bluetooth]# scan off
[...]
Discovery stopped
[CHG] Controller XX:XX:XX:XX:XX:XX Discovering: no
You may have to scroll up to find it, but if you gave it a friendly name ("Chamber 1" in my case), you should see the MAC followed by that name. Next, you will pair with your device with the pair command. It will prompt you to enter the code which is generally 1234 or 0000 unless you change it:
Code:
[bluetooth]# pair XX:XX:XX:XX:XX:XX
Attempting to pair with XX:XX:XX:XX:XX:XX
[CHG] Device XX:XX:XX:XX:XX:XX Connected: yes
Request PIN code
[agent] Enter PIN code: 1234
[CHG] Device XX:XX:XX:XX:XX:XX UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device XX:XX:XX:XX:XX:XX ServicesResolved: yes
[CHG] Device XX:XX:XX:XX:XX:XX Paired: yes
Pairing successful
[CHG] Device XX:XX:XX:XX:XX:XX ServicesResolved: no
[CHG] Device XX:XX:XX:XX:XX:XX Connected: no
[bluetooth]# trust XX:XX:XX:XX:XX:XX
[CHG] Device XX:XX:XX:XX:XX:XX Trusted: yes
Changing XX:XX:XX:XX:XX:XX trust succeeded
At this point your BT dongle is probably flashing once every two seconds. It's paired and trusted as you can see by issuing the 'info' command:
Code:
[bluetooth]# info XX:XX:XX:XX:XX:XX
Device XX:XX:XX:XX:XX:XX
        Name: Chamber 1
        Alias: Chamber 1
        Class: 0x001f00
        Paired: yes
        Trusted: yes
        Blocked: no
        Connected: no
        LegacyPairing: yes
        UUID: Serial Port               (00001101-0000-1000-8000-00805f9b34fb)
I noticed that if you power-cycle the BT dongle at this point, it will go back to flashing 2-3 times/second but that doesn't seem to affect things. You can exit or quit back to the shell prompt:
Code:
[bluetooth]# exit
Agent unregistered
[DEL] Controller XX:XX:XX:XX:XX:XX brewpi [default]
pi@brewpi:~ $
So, it's paired and trusted but still not visible in the device list:
Code:
pi@brewpi:~ $ ls -al /dev/rfc*
ls: cannot access '/dev/rfc*': No such file or directory
Next, we need to bind it to the device:
Code:
pi@brewpi:~ $ sudo rfcomm bind 0 XX:XX:XX:XX:XX:XX 1 > /dev/null 2>&1 &
[1] 3345
It seems like the command runs till something touches the device (which is why we background it with the trailing '&'.) In that command the '0' is the rfcomm device we want to assign, the MAC address should be obvious, and the 1 is the channel. Unless you know why you want to change this, use '1'. Now prove there is a device in the list (and see the background process exit):
Code:
pi@brewpi:~ $ ls -al /dev/rfc*
crw-rw---- 1 root dialout 216,  0 Mar 16 13:31 /dev/rfcomm0
[1]+  Done                    sudo rfcomm bind 0 XX:XX:XX:XX:XX:XX 1 > /dev/null 2>&1
pi@brewpi:~ $
Power-cycling the BT device at this point proves the device will reconnect after a power failure after about 10 seconds. What does not happen however is re-establish the device after a Pi reboot or power failure. We need a way to issue the rfcomm command after reboot (and after the bluetoothd starts.) Create a file named 'rfcomm0.service' in the '/etc/systemd/system/' directory and add the following information:
Code:
[Unit]
After=bluetooth.service

[Service]
ExecStart=/usr/bin/rfcomm bind 0 XX:XX:XX:XX:XX:XX 1 > /dev/null 2>&1 &

[Install]
WantedBy=default.target
This will allow systemd to execute the rfcomm command binding that MAC to rfcomm0 after the bluetooth.service starts. To enable this unit file, issue the commands:
Code:
pi@brewpi:~ $ sudo chown root:root /etc/systemd/system/rfcomm0.service
pi@brewpi:~ $ sudo chmod 664 /etc/systemd/system/rfcomm0.service
pi@brewpi:~ $ sudo systemctl daemon-reload
pi@brewpi:~ $ sudo systemctl enable rfcomm0
Created symlink /etc/systemd/system/default.target.wants/rfcomm0.service → /etc/systemd/system/rfcomm0.service.
pi@brewpi:~ $
You can start it with the 'sudo systemctl start rfcomm0' command, but there's no reason to since it's already bound. If you check the status of this daemon after system reboot it will not be running, because it ran once and exited - which is all we needed it to do:
Code:
pi@brewpi:~ $ sudo systemctl status rfcomm0
● rfcomm0.service
   Loaded: loaded (/etc/systemd/system/rfcomm0.service; enabled; vendor preset:
   Active: inactive (dead) since Sat 2019-03-16 13:43:59 CDT; 40s ago
  Process: 290 ExecStart=/usr/bin/rfcomm bind 0 XX:XX:XX:XX:XX:XX 1 > /dev/null 2>&1 & (code=exited, status=0/SUCCESS)
 Main PID: 290 (code=exited, status=0/SUCCESS)

Mar 16 13:43:59 brewpi systemd[1]: Started rfcomm0.service.
That's how you set up your BT devices now in Stretch! You'll notice that using the graphical interface is also not needed. Using this method, no additional packages are required as a matter of fact, all the packages are part of the stock distribution.

If you have multiple devices, you'd change the above steps using 1, 2, 3, etc., instead of 0. You would also need a systemd unit file for each device.
 
Last edited:
I thought you might also like to see what such a fancy setup looks like after the above work:

IMG-7013.JPG

:D

That's a gen-u-wine @CadiBrewer 1.1 shield right there ... waiting for an order for the 1.2 boards to clean things up.

The case is an extremely custom piece of work but I'd be happy to create one just like this for you for about $200. :p
 
[ETA: In order to "Future-Proof" this article, I have created a page for it on the BrewPi Remix website. You can read the most up to date version there.]

I wanted to share what I think is an easier way to initially setup the HC-05 for BrewPi use. What @day_trippr lined out in the beginning is still valid, however for some people (like me, I'm not ashamed to admit it) "whipping up" a voltage splitter is not necessarily straightforward. It also leverages an Arduino and special sketch to set up the BT device which intimidates some folks. I found a different way that's likely more straightforward for most Windows users.

On Amazon I found a package with an HC-05 Bluetooth Module, a case for that module, Dupont jumpers, and a CP2102 USB to TTL Converter for $12.99 on Prime. That seems like a pretty good deal and provides some pretty good value for a person new to it. When you get a drawer full of "crap", the Dupont wires certainly have less value, but I kinda like the case. So, I'm writing this with that USB to TTL Converter being used:
61hYYTMhO8L._SL1001_.jpg
DSD TECH HC-05 Bluetooth Module Kit with CP2102 USB to TTL Converter for Arduino


Buy that ... come back ... now we're ready.

Without further adieu, download some software. You'll probably need the CP2102 drivers, and to follow this you will definitely need the DSD TECH Bluetooth Tools Software. Download and install both of these (actually the "Bluetooth Tools" doesn't install, just unzip to a handy directory):
Don't plug the converter into the USB on your computer yet. Connect the TTL converter and the BT module like so:
61sDP2rK-0L._SL1001_.jpg

I actually used the 3.3v the first time, the module will run on 3.3-6v for VIN I believe, but the data channel needs to be 3.3 volts. No worries, the USB to TTL converter handles that for you. Here's the connections in text form:

Converter <-> BT Module
3v3 <-> VIN
TXD <-> RXD
RXD <-> TXD
GND <-> GND


Basically, remember to connect transmit to receive and vice versa. When you are ready and the jumpers are connected properly, connect the device and set programming mode (called "AT mode") by doing the following:

Input low level to PIN34, supply power to the module, input high level to PIN34, then the module will enter to AT mode. Just kidding, I have no idea what that means either. I promised this would be for mortals. :)
  1. Hold the button down on the Bluetooth Module (note about some of the modules sold elsewhere which are insulated with shrink-tube: You may have to cut the tube away from the button in order for it to function correctly)
  2. Plug in the USB to TTL Converter
  3. The light will come on for about a second, and then shut off
  4. Let go of the button on the Bluetooth Module
If you have done this correctly, the module should be flashing on and off slowly. Done incorrectly, the device will be flashing rapidly. If you don't get it the first time, unplug the converter and try again.

Now run the "DSD TECH Bluetooth Tools Software" you unzipped. You will be executing "SHTester.exe".
TestAT.PNG

  1. Select the last tab which is "HC-05".
  2. Drop down the UART box and select the port. On most systems there will be only one. If you have some other COM port device installed there may be more than one listed. If this is the case you will need to open Windows' "Device Manager", look under "Ports (COM & LPT)", and see what COM port is associated with the "Silicon Labs CP210x" device.
  3. Set Baud Rate to 38400, then click "Open".
  4. Click the "Test" button, and in the status windows you will see the "AT" command being sent and "OK" received. This will not work unless you are in AT mode (slow flashing). If you don't get anything back it's likely a Baud Rate mismatch. Click on "Close", select a different Baud Rate, "Open" and try testing again till you get an "OK" back.
  5. Now set "Bluetooth Name" to whatever you'd like it to be, Baud Rate to 57600, PIN (really no reason to change this but remember it), and set Role to "Slave". Click "Set" after each change.
  6. Now "Close" the UART up top again and you can close the app.
To test the device over BT:
  1. Unplug the USB dongle and unplug the two TX and RX wires.
  2. Plug it back in and now the Bluetooth Module will be flashing rapidly indicating it's ready to be paired.
  3. Open the Windows Bluetooth settings and click "Add a device."
  4. Select the name you gave the module above and enter the PIN you used.
  5. Click "Connect" and if successful, the device will flash briefly every two seconds or so.
Congratulations! You can unplug the device now, it's ready to be connected to your Arduino.

So this is where you can go a couple different ways. In order to connect you do need to use a voltage splitter so that the voltage on the communications circuit does not burn out. If you are using @CadiBrewer's shield, this is handled for you. Connect as follows:

Shield <-> BT Module
TXD <-> RXD
RXD <-> TXD
GND <-> GND
VCC <-> VIN


If you are going all rogue and want to do it without a shield, at least you were able to skip the whole Arduino sketch setup thing. You will need:
  • 1 x 1K ohm resistor (1/8W axial)
  • 1 x 2K ohm resistor (1/8W axial)
  • Dupont jumpers
Wire them according to this diagram which @day_trippr shared in the beginning so that the voltage into the RXD pin on the module is cut to 3.3v:
hc05_wiring_operating.jpg


The rest of the configuration is in this post above.
 
Last edited:
Back
Top