Showing posts with label socket. Show all posts
Showing posts with label socket. Show all posts

Wednesday, 25 June 2014

Mysql Systemd won't start woes

After a Gentoo reinstall on my laptop (Thinkpad T420), I configured my system to use Systemd and KDE with UEFI (no secure boot obviously).
It now boots in less than 7 seconds (!) but I do encounter the occasional issue. There is something to be said for the simplicity and stability of openrc.

One issue I've encountered isn't related to systemd insomuch as mysql isn't properly configured when I install it. Please note, it's not just mysql that is affected, but mariadb as well.


Problem is this:

/var/run/mysqld did not exist and it needs to be set to mysql:mysql ownership. Once I did those two things, systemd could start mysqld.

If those do not work, try the following:

cd /usr/
/usr/share/mysql/scripts/mysql_install_db
mkdir /var/run/mysqld
chown -R mysql:mysql /var/run/mysqld
systemd start mysqld
/usr/bin/mysql_secure_installation

On that last step, I had no root password so pressing Enter at the prompt passed that question.

I hope this helps.

Tuesday, 9 July 2013

Speedway Revolution 420 RFID Tag Reader in Python

So I recently was working on connecting a piece of software to a reader via a socket.

The vendors had a great script for connecting to it via ruby, as shown in the code below:

require 'socket'

s = TCPSocket.new '192.168.2.165', 14150

while line = s.gets
    puts line.chop
end

s.close


This code is available, you can see it here in the video:
http://learn.impinj.com/articles/en_US/RFID/Reading-Tags-over-TCP-IP-Socket-Using-Speedway-Connect-Software/

The site presents .NET code for connecting as well. However, as I do most of my work in python, I figured I'd keep things simple and convert their script to it.

---

The reason I'm writing this post is because I had one hell of a time getting to the point where it *would* read, because it would keep failing on the connect() method and from then on, I would have a Connection Refused error whenever I ran the python OR the ruby script. If you are having troubles with the Speedway Revolution 420 reader, know this:

* If you get Connection Refused errors, you need to browse to the ReaderConnect software, found at the reader ip address on port 8080. Click the save button, even if you haven't made any changes. This will allow connections to be received again, as I imagine it closes whatever broken connection python has left behind.
* You must use python 2.7 (or 2.x series, though I haven't tested beyond that) in order for it to run. When my code was failing, the header was "#!/usr/bin/env python", which on my linux mint system, would default to python 3. It was only until I *explicitly* stated "#!/usr/bin/env python2.7" that it miraculously worked. Here is the code:

#!/usr/bin/env python2.7

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.168.2.165", 14150))

data = s.recv(1024)
data = data.strip('\n')
while 1:
    print data
    data = s.recv(1024)
    data = data.strip('\n')
    
s.shutdown(socket.SHUT_RD)
s.close()


It makes two assumptions:

1. You want to read 1024 bytes. 0 does NOT work, it leaves me with an empty screen because the data variable does not get assigned to anything more than an empty string.
2. If you set the output to Linefeed, or Carriage Return Linefeed, this script will work. If you don't set the line ending value in the Output tab, there could be some issues.

Hopefully this script can help someone, someday.