Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to work with current API (2.1.9) and OS #8

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

sirkus7
Copy link

@sirkus7 sirkus7 commented Sep 16, 2020

Open Sprinkler API has changed, causing errors in opsiLCD.py. Updated
to work with v.2.1.9.

Also, fixed the network IP detection. Previous method of "hostname -I"
returned all addresses, including IPv6, with no guaranteed order. Now
uses the netifaces library and a defined variable for specifying which
interface will be used (wlan, eth0, etc.) The downside is that it
requires installation of netifaces. The upside is that this approach
should be relatively stable and future proofed from OS changes.
README updated to reflect library install requirement.

Open Sprinkler API has changed, causing errors in opsiLCD.py. Updated
to work with v.2.1.9.

Also, fixed the network IP detection. Previous method of "hostname -I"
returned all addresses, including IPv6, with no guaranteed order. Now
uses the netifaces library and a defined variable for specifying which
interface will be used (wlan, eth0, etc.) The downside is that it
requires installation of netifaces. The upside is that it should be
a bit more future-proof. Here's hoping.
@wifi75
Copy link

wifi75 commented Sep 18, 2020

Sorry @sirkus7 tell me how to update the Ospilcd.py file?

@sirkus7
Copy link
Author

sirkus7 commented Sep 19, 2020

@wifi75, for now it may be easiest for you to just clone my patched branch referenced above. Or you can visit my repo branch and just grab that file.

@stanoba
Copy link
Owner

stanoba commented Sep 25, 2020

Hi @sirkus7. Thanks for fixing ospiLCD script. 👍
I'll have a look at it once I build my testing environment.

@wifi75
Copy link

wifi75 commented Sep 26, 2020

Hello how i can update?

@stanoba
Copy link
Owner

stanoba commented Sep 26, 2020

@wifi75 Go to @sirkus7 fork https://github.com/sirkus7/ospiLCD/tree/api-update-2.1.9 and follow his updated instructions.
Download his updated script https://github.com/sirkus7/ospiLCD/blob/api-update-2.1.9/ospiLCD.py instead of mine.

@wifi75
Copy link

wifi75 commented Sep 27, 2020

@stanoba @sirkus7 hello
I follow this instruction: https://github.com/sirkus7/ospiLCD/blob/api-update-2.1.9/README.md
after set new script now this is my new error:
my network interface is wlan0

root@Opensprinkler:/home/pi# /home/pi/ospiLCD.py
Traceback (most recent call last):
  File "/home/pi/ospiLCD.py", line 52, in <module>
    ja = get_data(api_url)
  File "/home/pi/ospiLCD.py", line 48, in get_data
    variables = json.loads(data, object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
  File "/usr/lib/python2.7/json/__init__.py", line 352, in loads
    return cls(encoding=encoding, **kw).decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 380, in raw_decode
    obj, end = self.scan_once(s, idx)
  File "/home/pi/ospiLCD.py", line 48, in <lambda>
    variables = json.loads(data, object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
  File "/usr/lib/python2.7/collections.py", line 354, in namedtuple
    'keyword: %r' % name)
ValueError: Type names and field names cannot be a keyword: 'pass'
root@Opensprinkler:/home/pi#


Python pip is not included in all Raspian images and must first be
installed. Added pip to the existing apt isntall command, and moved it
to the beginning to make it work smoothly.
The new OpenSprinkler API responds with a parameter called "pass" which
is a keyword and therefore cannot be used to create an object.
Fixed by replacing "pass" term with "password" prior to deserializing
the JSON response.
@sirkus7
Copy link
Author

sirkus7 commented Sep 29, 2020

@wifi75 I tested on a new install and hit the same issue you did, so clearly I had some other differences on my system that allowed things to work. So thanks for pointing out that problem.
I found the problem and committed the fix. Grab the new one and try it again.

@wifi75
Copy link

wifi75 commented Sep 29, 2020

@sirkus7
do I buy the new file from here?
wget https://raw.githubusercontent.com/stanoba/ospiLCD/master/ospiLCD.py

after that operation same problem:

root@Opensprinkler:/home/pi# ./ospiLCD.py
Traceback (most recent call last):
  File "./ospiLCD.py", line 52, in <module>
    ja = get_data(api_url)
  File "./ospiLCD.py", line 48, in get_data
    variables = json.loads(data, object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
  File "/usr/lib/python2.7/json/__init__.py", line 352, in loads
    return cls(encoding=encoding, **kw).decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 380, in raw_decode
    obj, end = self.scan_once(s, idx)
  File "./ospiLCD.py", line 48, in <lambda>
    variables = json.loads(data, object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
  File "/usr/lib/python2.7/collections.py", line 354, in namedtuple
    'keyword: %r' % name)
ValueError: Type names and field names cannot be a keyword: 'pass'

@sirkus7
Copy link
Author

sirkus7 commented Sep 29, 2020

@wifi75 That's the old version. You can get the one I updated here:
https://github.com/sirkus7/ospiLCD/blob/api-update-2.1.9/ospiLCD.py

@wifi75
Copy link

wifi75 commented Sep 29, 2020

@sirkus7 ok yes now the script work but display it is black, where is on opensprinkler setting the light level?
once there was

@sirkus7
Copy link
Author

sirkus7 commented Sep 29, 2020

@wifi75 Haha, I honestly don't know where that setting can be found. I've only recently installed opensprinkler, and I haven't found the light level setting in the UI. It's possible it has been removed for the RPi version.

For my purposes, I turned the backlight on permanently because I couldn't find that feature. If that would be okay for you as well, you can add the following line of code at line 164 (in my version of the script) to turn the backlight on:
backlight = True

[Update: I corrected the line above]

@wifi75
Copy link

wifi75 commented Sep 30, 2020

that
lcd.backlight_enabled = True
in your ospi file ?

@sirkus7
Copy link
Author

sirkus7 commented Sep 30, 2020

Yes. Though, let me correct something. The line should be

backlight = True

So, If you've used my updated version of the ospiLCD.py file, and if you'd like the LCD backlight to be on all the time, then you can simply insert that one line of code at line into the ospiLCD.py file at line 164. Just to show that line in context, the new line of code is placed right before the lcd device is created to display the information, so it would look like this in the script.

backlight = True
lcd = i2c.CharLCD(i2c_expander=LCD_i2c_expander, address=LCD_i2c_address, port=1, cols=LCD_cols, rows=LCD_rows,
					dotsize=8, charmap='A02', auto_linebreaks=True, backlight_enabled=backlight)

The result will be that the backlight is always enabled. Hope that helps.

@wifi75
Copy link

wifi75 commented Sep 30, 2020

nice now work!
thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants