pylink.py fails after couple of updates

I have my emontx connected via serial link on my Rpi on the ttyAMA0. I am trying to run the pylink.py script and seem to work at least for one or two updates. Then it fails showing the message below.

pi@raspberrypi ~ $ ./pylink.py
0 8 2 3236
ok
5 9 2 3236
Traceback (most recent call last):
  File "./pylink.py", line 44, in <module>
    response = conn.getresponse()
  File "/usr/lib/python2.7/httplib.py", line 1034, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 407, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 371, in _read_status
    raise BadStatusLine(line)
httplib.BadStatusLine: ''
 

Obviously I believe my variables (apikey, serial etc...) in the python script are correct since it does succeed for at least one update (or scan).

I have tried adding a try statement to get the http request to be sent again but that still fails. According to my searches on the web this is failing when it gets a response from the server it does not understand. My apikey and domain variable both point to the Rpi http server (emoncms) itself.

Any ideas?

chacal's picture

Re: pylink.py fails after couple of updates

Solved it. The request string seem to miss a carriage return in the end. I modified the end of the script like so below:

  # Send to emoncms
  #conn.request("GET", "/"+emoncmspath+"/input/post.json?apikey="+apikey+"&node="+str(nodeid)+"&csv="+csv)
  conn.request("GET", "/%s/input/post.json?apikey=%s&node=%s&csv=%s\n" % (emoncmspath,apikey,str(nodeid),csv))
  response = conn.getresponse()
  print response.read()

 

It's been working solid for a while now.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.