1096RE: RSS reader thread...
- Oct 3 3:42 PM
If I could just now, I would.
Here's the code though. (Only about 50 lines !)CODEimport urllibimport serialimport timeser = serial.Serial()ser.port = "/dev/ttyAMA0"ser.baudrate = 9600ser.bytesize = serial.EIGHTBITS #number of bits per bytesser.parity = serial.PARITY_NONE #set parity check: no parityser.stopbits = serial.STOPBITS_ONE #number of stop bitsser.timeout = 1 #non-block readser.xonxoff = False #disable software flow controlser.rtscts = False #disable hardware (RTS/CTS) flow controlser.dsrdtr = False #disable hardware (DSR/DTR) flow controlser.writeTimeout = 2 #timeout for writeser.open()ser.write(chr(10))time.sleep(2) #pause 2 secsser.write("$B7E000000"+chr(13)+chr(10))time.sleep(1) # pause 1 secf= urllib.urlopen(u)contents = str(f.read())f.close()i=0ff = open('rssout.txt','w')while True:i = contents.find('<item>',i)if i == -1:breaki= contents.find('<title>',i+1)j= contents.find('</title>',i+1)message_title = contents[i+7:j]i= contents.find('<description>',i+1)j= contents.find('</description>',i+1)message_description = contents[i+13:j]i= contents.find('<pubDate>',i+1)j= contents.find('</pubDate>',i+1)message_date = contents[i+9:j]ff.write(' BBC ')ff.write(message_date+' ')ff.write(message_title+' ')ff.write(message_description+' '+chr(10))ff.close()f = open('rssout.txt','r')contents = f.readline()while contents !='':print(contents)l = len(contents)for i in range (1,l-6):ser.write("$B7M"+contents[i:i+6].upper()+chr(13))time.sleep(0.2)contents = f.readline()f.close()
---In firstname.lastname@example.org, <Thinwing@...> wrote:I WANT!...GIMME...kpcIn a message dated 10/3/2013 3:15:32 P.M. Pacific Daylight Time, fixitsan@... writes:
After a bit of playing, I present the Raspberry Pi/Smartsocket RSS reader
Making this has highlighted a few problems with the existing Smartsocket code. First, there are no lower case characters so I have to convert nice mixed case messages into all uppercase.
Another problem is that when there a bit punctuation comes along and you're trying to scroll it, there is a clash between the code trying to ignore the invalid punctuation and trying to display the last character. That is why in the video there are occasional double characters at the end of some words.
The Raspberry Pi TX pin connects via a 220Ohm resistor to the Smartsocket, as a precaution towards problems caused by the difference in system voltages , Raspberry Pi at 3.3V and PIC/Smartsocket at 5V.
I'm happy to have got this far and really pleased with Python as a language. So far this is just a proof of concept. Now the real work begins because somehow users need to interact with the unit. For example, if you see a feed scrolling past which you've read already, or which isn't of interest, then you ought to be able to perhaps press a button on a remote control to allow you to jump to the next message. Or maybe yoiu want to see the time ?
The method of operation is roughly as follows..
- Read the whole RSS page in XML format into one long string (Python seems to be able to cope with massive string lengths)
- Step through the string till the <item> tag is found , and then capture the date, time, Title and description...and then write that group of data as a single line in a text file (rssout.txt)
- Once the file is written, the lines are stepped through, one at a time. Each line is read 6-characters at a time and that 6 character wide window is scrolled along, step by step, and appended to a Smartsocket $B7M header.
Anyway, getting this far proves the hardware side of things, as well as proving that Python, Raspberry Pi, Raspbian OS and a wifi dongle all work well together. I haven't had a single website connection failure or a single wifi problem, so I'm really pleased with the reliability and robustness of this system.
- << Previous post in topic Next post in topic >>