1

What I am trying to do it make a GUI to control a raspberry pi bot. I have telnet to wirelessly connect to it. When I telnet to it from a terminal on my computer, I can run echo 1=230 > /dev/servoblaster to make one of the servos move.

However, when using that same piece of code in the python GUI, it does not make the servo move, but I don't get an error message either. At one point it was all working but then suddenly it stopped.

Below is a simplified version of the python script that I am using for my GUI:

from tkinter import *
import telnetlib

bot = telnetlib.Telnet("192.168.1.128")
bot.read_until(b"login: ")
bot.write(("pi \n").encode('ascii'))
bot.read_until(b"Password: ")
bot.write(("pi \n").encode('ascii'))
bot.write(("cd /home/pi/pibits/ServoBlaster/user \n").encode('ascii'))
bot.write(("sudo ./servod \n").encode('ascii'))
bot.write(("cd \n").encode('ascii'))

bot.write(("echo 1=230 > /dev/servoblaster \n").encode('ascii'))

Would someone be able to help me work out why when I connect to the bot from a terminal I can control it but when running the same command with the above code nothing happens, not even an error message.

Just in case this is of any use, I know the above code is at least reaching the wireless receiver of my raspberry pi because the lights on it flash every time it receives a signal.

Thanks

4

2 回答 2

3

Your space in the username and password commands are keeping your telnet session from actually logging into the pi bot. The spaces aren't ignored.

You need:

bot.read_until(b"login: ")
bot.write("pi\n".encode('ascii'))
bot.read_until(b"Password: ")
bot.write("pi\n".encode('ascii'))
于 2014-06-29T22:42:08.607 回答
2

I'd recommend using Wireshark to figure out what is actually is being sent by your client and what does your Raspberry Pi respond.

I strongly suspect the cause of your problem is that you are waiting for wrong pattern — e.g. it may be b'Login: ', or b'login:', or anything else, and that may change with updating your getty or similar binary, and Wireshark will help you localize your problem.

To see only telnet traffic with your Pi box, use following capture filter:

host 192.168.1.128 and port 23
于 2014-06-29T22:06:30.400 回答