Skip to main content

Temper Temperature monitor on a Beaglebone Black

Beaglebone Black as a temperature monitor:

Recently I wanted to monitor the temperature of my shed.  I thought I'd use a small computer such as a Raspberry Pi or a Beaglebone or Odroid.

My Raspberry Pi boxes were all in use, so I grabbed my Beaglebone, which was doing nothing.

I flashed it with the Debian 9.3  4GB SD IoT image, but that seemed like it was running lots of bloatware and the ethernet interface wouldn't take a static IP with /etc/network/interfaces.

So I went with the Debian 9.3  4GB SD LXQT i image instead.  I still had the same problem, that lots of junk was running, and I couldn't configure my interface by modifying /etc/network/interfaces

So my first step was to get rid of all the bloatware.  If you're using a Raspberry Pi or something, you can skip this and just go to the second step below

STEP 1--Remove Blotatware from Beaglebone Black:

With some searching, I came across this post:
https://www.linuxquestions.org/questions/linux-newbie-8/internet-connection-between-linux-and-windows-4175598230/page2.html#post5661095

with a cable plugged into your ethernet port (or else you won't see it), run:
connmanctl services

you will see your ethernet device there as ethernet_xxx, like the below

That said to simply run these two commands to fix your IP:
connmanctl config ethernet_9059af4beffc_cable --ipv4 manual 192.168.137.2 255.255.255.0 192.168.137.1

connmanctl config ethernet_9059af4beffc_cable --nameservers 192.168.1.1 8.8.8.8

connmanctl config ethernet_9059af4beffc_cable --ipv6 off

I also deleted the USB stuff from /opt/scripts/boot/autoconfigure_usb*.sh, since I wasn't using them

That fixed my static IP address problem, but I still had tons of stuff running when I did a netstat -pant.   Thus, I uninstalled apache2 and dnsmasq with:

'apt-get remove apache2'
'apt-get remove dnsmasq'

Then, there are tons of services running.  You can see them with:
ls /lib/systemd/system
One way to get rid of stuff is to just delete it from the above directory.
i.e rm -rf /lib/systemd/system/bonescr*
cloud9*
node-red*
etc

Or,  you might stop them with:
systemctl disable bonescript.socket
systemctl disable bonescript.service
systemctl disable bonescript-autorun.service
systemctl disable node-red.service
systemctl disable cloud9.service
systemctl disable gateone.service
systemctl disable bonescript.service
systemctl disable bonescript.socket
systemctl disable bonescript-autorun.service
systemctl disable avahi-daemon.service
systemctl disable gdm.service
systemctl disable mpd.service

Then, when I ran a netstat -ant I only had sshd running.  Clean.

After that I updated my distro with:
apt-get update

STEP TWO--Get TEMPerr Thermometer working:

Then it was time to try to get my TEMPer USB Thermometer working.   I tried several git repositories, and could not get it to work.  Luckily, my friend Matt, who is an 'Electronic Jesus,' jumped in and saved the day.

Since the device registered as a HID device, he used he hidapi to talk to it.  To install the hidapi:
sudo apt-get install python-dev libusb-1.0-0-dev libudev-dev
sudo pip install --upgrade setuptools
sudo pip install hidapi
Be warned... the pip install of hidapi takes anywhere from 30 minutes to an hour or more... so be patient.

Then you should be able to try his python script (in blue below) to see if it will run:

from __future__ import print_function
import hid
import time

# enumerate USB devices

path = None

for d in hid.enumerate():
    keys = list(d.keys())
    keys.sort()
    if d["product_id"] == 8455 and d["interface_number"] == 1:
        print("Found the temper")
        path = d["path"]
        break
    #for key in keys:
    #print("%s : %s" % (key, d[key]))

print("path ", path)

# try opening a device, then perform write and read

if path:
 try:
    print("Opening the device")

    h = hid.device()
    #413d:2107
    #h.open(0x413d, 0x2107) # TREZOR VendorID/ProductID
    h.open_path(path)

    #print("Manufacturer: %s" % h.get_manufacturer_string())
    #print("Product: %s" % h.get_product_string())
    #print("Serial No: %s" % h.get_serial_number_string())

    # enable non-blocking mode
    #h.set_nonblocking(1)

    # write some data to the device
    #print("Write the data")
    while True:
    
        h.write([0, 1, 0x80, 0x33, 0x1] + [0] * 4)

        # wait
        time.sleep(0.05)

        # read back the answer
        #print("Read the data")
        d = h.read(20, 4000)
        if not d:
            continue
            #print("no data")

        print(d)
        #This corrects for negative Celsius values
        if d[2] > 0x7f:
            d[2] = d[2] - 256
        temp = ((int(d[2]) << 8) + int(d[3])) / 100.0
        temp = temp*9.0/5.0 + 32.0

        humidity = ((int(d[4]) << 8) + int(d[5])) / 100.0

        print("Temp is ", temp, " humidity is ", humidity)
        time.sleep(1)
    h.close()

 except IOError as ex:
    print(ex)
    print("You probably don't have the hard coded device. Update the hid.device line")
    print("in this script with one from the enumeration list output above and try again.")

print("Done")


Since Matt is so good, this, not surprisingly, worked out of the box to give me the temperature.   I was a little surprised to see that the device said it was hotter than it was.  It seemed like the heat from the USB connection was causing it internal to the TEMPer USB device.  I say internal because I took a laser themometer and shot it at the USB and it would register colder than it was reading.

Anyway, as the device seemed to be getting heat from the Beaglebone through the USB port pins, a fix that worked was just using a USB extender cable.

I now have a device that records the temperature once per minute and stores that in a file.  If you'd like that code (based on Matt's code above), it's posted below.    Here's a sample of its output first, with the date/time and temperature separated by a comma so you can put it in Excel easily:

root@beaglebone:/home/debian# tail TempRecord.csv 
2018-07-01 08:45,63.4
2018-07-01 08:46,63.5
2018-07-01 08:47,63.5
2018-07-01 08:48,63.6
2018-07-01 08:49,63.6
2018-07-01 08:50,63.7
2018-07-01 08:51,63.7
2018-07-01 08:52,63.7
2018-07-01 08:53,63.7
2018-07-01 08:54,63.7


If you'd like the code, here it is.  Enjoy!:

root@beaglebone:/home/debian# cat RecordTemp.py
#!/usr/bin/python

# This script is designed to read from a TEMPer USB Themometer, and
# reecord the data to the hard drive every minute


from __future__ import print_function

import hid
import time
import datetime
import sys # needed to flush print queue

# enumerate USB devices

path = None
bufsize = 0

for d in hid.enumerate():
    keys = list(d.keys())
    keys.sort()
    if d["product_id"] == 8455 and d["interface_number"] == 1:
        print("Found the temper")
        path = d["path"]
        break
    #for key in keys:
    #print("%s : %s" % (key, d[key]))

print("path ", path)

# try opening a device, then perform write and read


if path:
 try:
    print("Opening the device")

    h = hid.device()
    #413d:2107
    #h.open(0x413d, 0x2107) # TREZOR VendorID/ProductID
    h.open_path(path)

    #print("Manufacturer: %s" % h.get_manufacturer_string())
    #print("Product: %s" % h.get_product_string())
    #print("Serial No: %s" % h.get_serial_number_string())

    # enable non-blocking mode
    #h.set_nonblocking(1)

    # write some data to the device
    #print("Write the data")
    writefile = open("/home/debian/TempRecord.csv", "a", bufsize)
    while True:
        now = datetime.datetime.now()
        now = now.strftime("%Y-%m-%d %H:%M")
        h.write([0, 1, 0x80, 0x33, 0x1] + [0] * 4)
        #sys.stdout.flush()
        # wait
        time.sleep(1)

        # read back the answer
        #print("Read the data")
        d = h.read(20, 4000)
        if not d:
            continue
            #print("no data")

        #print(d)
        temp = ((int(d[2]) << 8) + int(d[3])) / 100.0
        temp = temp*9.0/5.0 + 32.0
        temp = round(temp,1)

        humidity = ((int(d[4]) << 8) + int(d[5])) / 100.0

        toprint = (str(now) + "," + str(temp))
        print(toprint)
        writefile.write(toprint+"\n")
        sys.stdout.flush()
        time.sleep(59)
    h.close()

 except IOError as ex:
    print(ex)
    print("You probably don't have the hard coded device. Update the hid.device line")
    print("in this script with one from the enumeration list output above and try again.")

print("Done")





Comments

  1. Nice blog... Server temperature monitor measure temperature, humidity, power. Receive temp alerts via SMS and Email.

    ReplyDelete
  2. Good day. I was impressed with your article. Keep it up . You can also visit my site if you have time. Thank you and Bless you always.


    hp officejet pro 6968 wireless setup

    ReplyDelete
  3. Good information. It will be usefull for me, keep sharing more also visit our Printer setup and troubleshoot Guide.

    ReplyDelete

Post a Comment

Popular posts from this blog

atftpd vs tftpd-hpa

Recently I was trying to tftp files from a Windows computer to a Kali box.   One version of Windows worked, but another didn't.    After much troubleshooting, here were my symptoms:

I could tftp a file from-to any Kali box from-to another Kali box
I could NOT tftp files to a specific Windows 7 box from any Kali box
I could NOT tftp files to a Chrooted-Ubuntu-Chromebook box from a Kali box

After MUCH troubleshooting, going through every setting in atftpd, it seemed like it literally was a client OS problem.  Different clients simply would not download files---unacceptable.

Thus, I switched to tftpd-hpa.   To install:
apt-get install tftpd-hpa

files go to/come from /srv/tftp, but it needs to be a tftp user. Thus, I needed to:
chroot -R /srv/tftp

Also, if you want to be able to put files ON the tftp server (from a client), you need to modify /etc/default/tftpd-hpa:
change "TFTP_OPTIONS="--secure" to "TFTP_OPTIONS="--secure --create"

I also changed the IP li…

ADS-B plotting with Kali (and other SDR goodies)

Recently I wanted to try some Software Defined Radio stuff.   
I had a RTL-SDR, FM+DAB, DVB-T USB Stick Set with RTL2832U & R820T. that I got from: http://www.amazon.com/gp/product/B00C37AZXK/ref=oh_details_o04_s00_i00?ie=UTF8&psc=1
But, even though this dongle would break out FM radio stations, and ATC frequencies (like the local Ground Control, tower, and even ATIS), which was cool, it wouldn't break out ADS-B.   
Thus, I bought a Vantech Green Mini RTL2832U R820T DVB-T SDR DAB FM USB DIGITAL TV Tuner Receiver RTL-SDR Project + DAB dongle Tuner MCX Input from Amazon, and tried this.  
This dongle was able to listen to the 1090MHz frequency required for ADS-B (as it goes from 25MHz to 1700MHz).  There were tons of Windows programs out there for breaking out and plotting ADS-B Mode S broadcasts, but not many for Linux.  
For Kali Linux, here's how I got it running and plotting planes around my home:
0) before you start, you should do an apt-get update to ensure you hav…