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 2018-03-05 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 2018-01-28 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:
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
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:
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")
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 2018-03-05 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 2018-01-28 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")
Nice blog... Server temperature monitor measure temperature, humidity, power. Receive temp alerts via SMS and Email.
ReplyDeletehttps://setup-wireless-printer.com/hp-laserjet-ultra-m106w-wireless-driver-mac/
ReplyDeleteBtree System
ReplyDeleteaws 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.
ReplyDeleteIOT 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.
Organic Chemistry
ReplyDelete
ReplyDeleteorganic chemistry notes