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. aws training in chennai - AWS Amazon web services is a Trending Technologies and one of the most sought after courses.Join the Best Aws course in Chennai now.

    IOT training in chennai - Internet of things is one of best technology, Imagine a world with a Internet and everything minute things connected to it .

    DevOps Training Institute in Chennai - Just from DevOps course Best DeVops training Institute in Chennai is also providing Interview Q & A with complete course guidance, Join the Best DevOps Training Institute in Chennai.

    Load runner training in Chennai - Load runner is an software testin tool. It is basically used to test application measuring system behaviour and performance under load. Here comes an Opportunity to learn Load Runner under the guidance of Best Load Runner Training Institute in Chennai.

    apache Spark training in Chennai - Apache Spark is an open- source, Split Processing System commonly used for big data workloads. Learn this wonderful technology from and under the guidance of Best Apache spark Training Institute in Chennai.

    mongodb training in chennai - MongoDB is a cross platform document - oriented database Program. It is also classified as NO sql database Program. Join the Best Mongo DB Training Institute in Chennai now.

    ReplyDelete

Post a Comment

Popular posts from this blog

HP c6180 Printer and Vista

Hp c6180 driver issues with Vista Home Premium My wife has a Vista Home Premium laptop, and the HP C6180 Photosmart printer keeps disappearing from her available printers.  The only way I've found to fix the problem is to reinstall all the HP software. When I do this, I have to download the (large..507M software from HP, or reinstall the printer (ONLY the printer, not the scanner) with the installation disk, as the drivers are not discovered with a "Windows Update" setting.  My guess is that is because HP doesn't like people to install only the printer driver, which would be easy, but they want folks to install all their crapware as well, so they are withholding the drivers from the on-line Microsoft printer database.  So keep your installation CD!  I've also found that unless I install everything on the CD or in the Full Version download (HP Customer Participation Program, HP Imaging Device functions, HP OCR SW, HP All-In-one SW, HP Photosm...

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" ...

Security Onion on the Antsle

My Setup of Security Onion on the Antsle: Recently my IDS box, an Intel Atom D2500 Fanless Mini-ITX PC, D2500CCE, died.  Truth be told, I think it came from the factory in a bad state, as I originally thought I had a bad graphics driver, but I then noticed that, after much troubleshooting, it wasn't a driver issue at all.  The box just sometimes wouldn't boot up correctly with video.  It seems heat related, something like not enough thermal paste on the CPU, as after it is powered off for a while it is more likely to boot than when it is warm.  Along with that issue, this box maxed out at 4GB of RAM (only has 2 memory slots, each of which will only take a 2GB card max) and had a single processor, so it was under powered for Security Onion. So, I decided to quit limping along on P.O.S. boxes, and buy a little more heavyweight box for my networked IDS.   Security Onion requires a minimum of 8GB of RAM, and 4 cores per their specs page htt...