tiramiseb / python-openevse

Python library for the OpenEVSE RAPI protocol
MIT License
23 stars 10 forks source link

Many commands don't work #3

Closed stopeject closed 5 years ago

stopeject commented 5 years ago

First of all, I'm not a coder, so it could be an user error. I'm trying to write a simple script to set the charge time limit automatically every time the EVSE is charging. I can't get to work some commands:

$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import openevse
>>> ev= openevse.WifiOpenEVSE('10.0.0.7')
>>> print ev.version()
{'firmware': '4.8.0', 'protocol': '3.0.1^2E'}
>>> print ev.current_capacity()
32
>>> ev.current_capacity(34)
34
>>> print ev.current_capacity()
34
>>> print ev.status()
sleeping
>>> ev.status('enable')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/gt/.local/lib/python2.7/site-packages/openevse.py", line 238, in status
    raise EvseError
openevse.EvseError
>>> print ev.temperature()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/gt/.local/lib/python2.7/site-packages/openevse.py", line 570, in temperature
    'tmp007temp': float(data[2])/10
>>> print ev.elapsed()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/gt/.local/lib/python2.7/site-packages/openevse.py", line 591, in elapsed
    raise NotCharging
openevse.NotCharging

Please help to figure this out.

vintozver commented 5 years ago

I will check with my evse and will fix if necessary.

vintozver commented 5 years ago

I just noticed this is wifi extension, can you help me providing the command log?

I'm using plain serial connection and don't have this problem.

You may add the print() statements in the _get_response()

I'm particularly interested if the wifi protocol response has any deviations from the plain serial connection.

stopeject commented 5 years ago

I would be happy to help in any way I can, but I will need a bit more hand holding. What exactly should I do? Edit .local/lib/python2.7/site-packages/openevse.py and add something under the _get_response() function?

stopeject commented 5 years ago

If you want to check it out, I can get you remote access.

vintozver commented 5 years ago

I will prepare a couple of curl commands so you will execute them from the console and provide the output. I will be back from an intl trip within a day.

stopeject commented 5 years ago

Any time.

vintozver commented 5 years ago

Please exec a command in the linux console (have curl installed) and provide the command output

curl -vvv "http://10.0.0.7/r?rapi=%24FE"

This command will effectively enable your EVSE

Please also exec

curl -vvv "http://10.0.0.7/r?rapi=%24GV"

and provide its output.

Thank you very much for your assistance.

stopeject commented 5 years ago
curl -vvv "http://10.0.0.7/r?rapi=%24FE"
*   Trying 10.0.0.7...
* TCP_NODELAY set
* Connected to 10.0.0.7 (10.0.0.7) port 80 (#0)
> GET /r?rapi=%24FE HTTP/1.1
> Host: 10.0.0.7
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Length: 519
< Content-Type: text/html
< Access-Control-Allow-Origin: *
< Cache-Control: no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0
< Connection: close
< Accept-Ranges: none
<
<html><font size='20'><font color=006666>Open</font><b>EVSE</b></font><p><b>Open Source Hardware</b><p>RAPI Command Sent<p>Common Commands:<p>Set Current - $SC XX<p>Set Service Level - $SL 1 - $SL 2 - $SL A<p>Get Real-time Current - $GG<p>Get Temperatures - $GP<p><p><form method='get' action='r'><label><b><i>RAPI Command:</b></i></label><input id='rapi' name='rapi' length=32><p><input type='submit'></form>$FE<p>&gt;$OK^20<script type='text/javascript'>document.getElementById('rapi').focus();</script><p></html>

* Closing connection 0

curl -vvv "http://10.0.0.7/r?rapi=%24GV"
*   Trying 10.0.0.7...
* TCP_NODELAY set
* Connected to 10.0.0.7 (10.0.0.7) port 80 (#0)
> GET /r?rapi=%24GV HTTP/1.1
> Host: 10.0.0.7
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Length: 531
< Content-Type: text/html
< Access-Control-Allow-Origin: *
< Cache-Control: no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0
< Connection: close
< Accept-Ranges: none
<
<html><font size='20'><font color=006666>Open</font><b>EVSE</b></font><p><b>Open Source Hardware</b><p>RAPI Command Sent<p>Common Commands:<p>Set Current - $SC XX<p>Set Service Level - $SL 1 - $SL 2 - $SL A<p>Get Real-time Current - $GG<p>Get Temperatures - $GP<p><p><form method='get' action='r'><label><b><i>RAPI Command:</b></i></label><input id='rapi' name='rapi' length=32><p><input type='submit'></form>$GV<p>&gt;$OK 4.8.0 3.0.1^2E<script type='text/javascript'>document.getElementById('rapi').focus();</script><p></html>

* Closing connection 0

By the way, RAPI commands also work without encoding the $- sorry, upon more careful look at the output, the command didn't work.

`

vintozver commented 5 years ago

let me check the regex since there's a mix of html and the actual response.

Thx for bringing this up, really appreciate.

I will follow up within couple days.

vintozver commented 5 years ago

Please check the recent merge by another contributor. If works - we close the issue. Thx.

stopeject commented 5 years ago

I'm afraid I'm not a good tester here because I don't know enough about python. I noticed that latest commit is not on pypi and can't be installed with pip. So I tried to add the new script manually by copying it into /home/user/.local/lib/python2.7/site-packages/ folder. Apparently this is not how it needs to be done because I can't import the module

$python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import openevse
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "openevse.py", line 101, in <module>
    import urllib.request
ImportError: No module named request
vintozver commented 5 years ago

pip3 install git+https://guthub.com/........

vintozver commented 5 years ago

using python2 is discouraged, python2 is no longer supported. use "six" or 3to2 if python2 usage is mandatory for you.

stopeject commented 5 years ago

Thanks, everything worked! I tested all "get" commands, no errors. Changing 'current_capacity' also worked. I haven't tried other "set" commands yet. Thanks again for your help.

I want to ask an unrelated question. I need to check if the EVSE is connected to a vehicle while the charging is not permitted by setting the state to 'sleeping' or 'disable'. I couldn't figure out how to do it except by enabling EVSE for a short duration. But it will cause the contactors in both EVSE and a car to cycle, which is not desirable. Maybe I'm missing something and you know some other way to get that parameter.

vintozver commented 5 years ago

There is a callback function which reports the state change. I'm not sure if pilot is enabled while the EVSE is in disabled state, you can check it with the multimeter or oscilloscope. If pilot is present then it's physically possible.

stopeject commented 5 years ago

I think that the presence of the pilot will direct the car to start charging. There is also a proximity sensor https://openev.freshdesk.com/support/solutions/articles/6000052074-basics-of-sae-j1772, but it seems like its status can't be read with RAPI.

vintozver commented 5 years ago

pilot an and proximity are on the same line, PP evse will energize the circuit when it detects the voltage drop on the pilot (proximity). It's evse's decision to start the charge.

look for callbacks (status changes).

stopeject commented 5 years ago

It looks like Proximity is on a separate wire, but it is not implemented in OpenEVSE. I'll read on callbacks, thanks.