OpenLEADR / openleadr-python

Python library for OpenADR
https://openleadr.org/docs
Apache License 2.0
133 stars 51 forks source link

How to install the software #39

Closed arijeetr96 closed 3 years ago

arijeetr96 commented 3 years ago

I am interested to work with openLEADR for demand-side management purposes, but how to install the software in python? I just want some steps (manual) on how it will work.

How VTN will trigger, is there any web interface has been made for this where user can see the graphical user interface? please respond to me, I am highly interested to explore open ADR.

stan-janssen commented 3 years ago

There is no GUI and OpenLEADR is not ready-to-run software. It is a Python package that allows you to build your own OpenADR clients and servers yourself.

I might develop a small "demo" application with a GUI that you can run sometime next year, but the main focus will be on making the underlying package better.

arijeetr96 commented 3 years ago

Thanks for replying, recently I watched your video on youtube where you explaining how to work in open ADR through python. a good example you provided flexible devices and nonflexible devices control. I have a question, I would like to create a simple event for controlling the power devices by keeping ven side (raspberry pi) which can trigger the power devices along through python just what you described on youtube.

Is it okay to use that open source code open ADR by python? give me confirmation

stan-janssen commented 3 years ago

Sure, feel free to use what you saw in the YouTube video. You'll also find many examples and snippets in our documentation. If you run into any trouble, please let me know by adding to this issue. Good luck!

arijeetr96 commented 3 years ago

Thank you so much.I will stay connect with to you , and I am going to install the platform on Linux (ubuntu). Can you tell me which version do I need to install because I have windows based os so I will work through virtual box ,which ubuntu version will required ? please clarify.

stan-janssen commented 3 years ago

You can use openleadr with Windows as well if you want.

(I'm not sure what your skill level is and if you already have python installed, so I will try to give you the basic steps here. Please follow up if anything is unclear.)

  1. First, check if you have the correct Python version installed in Windows. Open cmd.exe and run python --version. You should have at least version 3.7, but 3.8 or 3.9 are recommended. If this command does not work, check if you have Python installed and check if Python is appended to your windows PATH. If it is not, you can run the installer again and make sure you check the box at the bottom that says "Add Python 3.X to PATH". More info is here.
  2. You then install the openleadr package using pip by running python -m pip install openleadr.
  3. You then create a new python file (don't call it openleadr.py, but call it something else like ven.py).
  4. In that file, you can begin building your VEN by importing from the openleadr package (from openleadr import OpenADRClient). Please see the documentation for examples.
  5. You can then run your VEN using the command python ven.py.
  6. The same goes for the VTN, you put the VTN code in a separate file (like vtn.py), and run it side-by-side from a second cmd.exe window.

If you want to use Ubuntu, I'm using Ubuntu 18.04, but if you're picking one right now, you should use the latest (20.04), which also includes an up-to-date version of Python I believe. If you want Linux instructions, let me know.

arijeetr96 commented 3 years ago

Thanks for the update. On my pc, I have installed it already in python (version 3.8.5). second, for ubuntu, I have windows based operating system so I have installed a virtual box that runs the ubuntu 20.4 LTS. For the third Linux based I have no idea that. please recommend me which I have I should go for, please make sure all security concern should matter on high priority means if I am running this software on windows or ubuntu. so you can give me better advice which os I should choose?

stan-janssen commented 3 years ago

Let's clear up some confusion first:

You would be well off to start developing your application on Windows, since you are already familiar with that. That would be my recommendation. You can later transfer the python files to your raspberry pi (which runs Raspbian, which is also Linux), and run them on there.

arijeetr96 commented 3 years ago

Okay great.

I am going to start installing software before reading the documentation. if I failed or facing any trouble, I will inform you. there is another way to talk with you email I'd... actually, if I faced any problem share any confidential information on this platform.

stan-janssen commented 3 years ago

You can also reach me at team@openleadr.org if you want to take this discussion off this page. Thanks!

arijeetr96 commented 3 years ago

okay, thanks.

arijeetr96 commented 3 years ago

Hii, I was running the code only basic try to connect server client to check. but given URL is giving error. see what I have a run a code.

for ven code.

import asyncio
from openleadr import OpenADRClient
client=OpenADRClient(ven_name='myven',vtn_url='http://some-vtn.com/OpenADR2/Simple/2.0b')
loop=asyncio.get_event_loop()
loop.create_task(client.run())
loop.run_forever()

for vtn code.

import asyncio
from openleadr import OpenADRServer
server=OpenADRServer(vtn_id='myvtn')
loop=asyncio.get_event_loop()
loop.create_task(server.run_async())
loop.run_forever()

errors pop up. In ven terminal side Could not connect to a server with URL http://some-vtn.com/OpenADR2/Simple/2.0b: ClientConnectorError: Cannot connect to host some-vtn.com:80 SSL:default [getaddrinfo failed] No VEN ID received from the VTN, aborting.

in vtn terminal side raise OSError(err.errno, 'error while attempting ' OSError: [Errno 10013] error while attempting to bind on address ('127.0.0.1', 8080): an attempt was made to access a socket in a way forbidden by its access permissions

please help me for this show to solve

stan-janssen commented 3 years ago

Okay there are two problems here:

From these questions, it seems like this may be your first time building this kind of application? My best advice is: take it slow. Try to go step by step, there's a lot of learning still left to do. Try to understand the error messages.

The VEN already told you what the problem was: it could not connect to some-vtn.com, which should make you think: "why is it trying to connect to this specific address anyway? It should be connecting to a VEN that I'm running on my local machine, which is localhost, not some-vtn.com".

The VTN also gave you a helpful error, at least if you know what is going on. The VTN includes a web server that tries to listen on a port (in this case port 8080 on your local machine, which is 127.0.0.1), and the operating system tells you that you cannot use that port. This is a negotiation between your application and the Operating System. The OS keeps track of all the ports that are in use and which applications are listening on them. It also manages which applications are allowed to bind to a certain port.

If any of these terms are unfamiliar to you, please look them up.

arijeetr96 commented 3 years ago

see I am going very slowly, I just want to run basic code which can connect ven and vtn then afterwards I will take step by step to add more steps just like I haven't added any certificates no keys till yet no handling event till yet. just want to run the two codes. can you help me with that?

arijeetr96 commented 3 years ago

I detected the error , but I changed the URL address http://localhost:8080/OpenADR2/Simple/2.0b but same error is coming.

arijeetr96 commented 3 years ago

I have to change the port number also, can you tell me if there is more lines that need to be added in the above two codes.

stan-janssen commented 3 years ago

I don't have the time to take you through every single step, but this should work:

# ven.py

import asyncio
from openleadr import OpenADRClient

client = OpenADRClient(ven_name='myven',
                       vtn_url='http://localhost:8181/OpenADR2/Simple/2.0b')

loop = asyncio.get_event_loop()
loop.create_task(client.run())
loop.run_forever()
#vtn.py

import asyncio
from openleadr import OpenADRServer

server = OpenADRServer(vtn_id='myvtn',
                       http_port=8181)

loop=asyncio.get_event_loop()
loop.create_task(server.run_async())
loop.run_forever()

Then, you first start up the server (vtn.py). If that still gives the OSError, you need to fix that first. I cannot help you with that; there must be some configuration that prevents you from binding to a port. I've not seen that happen myself, but it's probably some security setting.

If the VTN has started, it will print the URL that it is reachable at.

Then, you can start the VEN. It should be able to connect to the VTN, and then the VTN will show a warning that you haven't yet configured a on_create_party_registration handler, and it will reject the client.

The VEN will then tell you that it did not receive a venID from the VTN, and that's that.

arijeetr96 commented 3 years ago

Hello, I am trying to create a registration for ven, but when I am executing the code I am not getting any ven id. I had already created the handler line in the van code. please have a look and help me.

for vtn code...

import asyncio
from openleadr import OpenADRServer

async def on_create_party_registration(registration_info):
    if registration_info['ven_name'] == 'ven123':
        ven_id='ven_id_123'
        registration_id = 'reg_id_123'
        return ven_id,registration_id
    else:
        return False

server = OpenADRServer(vtn_id='myvtn',http_port=8181)
server.add_handler('on_create_party_registration',on_create_party_registration)

loop=asyncio.get_event_loop()
loop.create_task(server.run_async())
loop.run_forever()

After running in the terminal I am getting no error just getting output URL link where it shows in web page 404 error. for ven code I am struggling, please check in this one...

import asyncio
from openleadr import OpenADRClient
client = OpenADRClient(ven_name='ven123',vtn_url='http://localhost:8181/OpenADR2/Simple/2.0b')

loop = asyncio.get_event_loop()
loop.create_task(client.run())
loop.run_forever()

running in the terminal

python ven.py Execution of job "OpenADRClient._poll (trigger: cron[hour='', minute='', second='/10'], next run at: 2020-12-18 16:33:19 IST)" skipped: maximum number of running instances reached (1) Execution of job "OpenADRClient._poll (trigger: cron[hour='', minute='', second='/10'], next run at: 2020-12-18 16:33:20 IST)" skipped: maximum number of running instances reached (1)

sir, please help me with that where I am wrong

arijeetr96 commented 3 years ago

for ven, I have edited,

import asyncio
from openleadr import OpenADRClient
client = OpenADRClient(ven_name='ven123',vtn_url='http://localhost:8181/OpenADR2/Simple/2.0b')
async def on_create_party_registration(http_pull_model=True,xml_signature=False,report_only=False,profile_name='2.0b',transport_name='simpleHttp',transport_address='http://localhost', ven_id=None):
    loop = asyncio.get_event_loop()
    loop.create_task(client.run())
    loop.run_forever()

but nothing works please help me out..........

stan-janssen commented 3 years ago

Hello, I am trying to create a registration for ven, but when I am executing the code I am not getting any ven id. I had already created the handler line in the van code. please have a look and help me.

for vtn code...

import asyncio
from openleadr import OpenADRServer

async def on_create_party_registration(registration_info):
    if registration_info['ven_name'] == 'ven123':
        ven_id='ven_id_123'
        registration_id = 'reg_id_123'
        return ven_id,registration_id
    else:
        return False

server = OpenADRServer(vtn_id='myvtn',http_port=8181)
server.add_handler('on_create_party_registration',on_create_party_registration)

loop=asyncio.get_event_loop()
loop.create_task(server.run_async())
loop.run_forever()

After running in the terminal I am getting no error just getting output URL link where it shows in web page 404 error. for ven code I am struggling, please check in this one...

import asyncio
from openleadr import OpenADRClient
client = OpenADRClient(ven_name='ven123',vtn_url='http://localhost:8181/OpenADR2/Simple/2.0b')

loop = asyncio.get_event_loop()
loop.create_task(client.run())
loop.run_forever()

This code looks fine to me. I ran this exact code on my machine and it works as it should. After starting the VTN and the VEN, you don't see any more text in your terminal. If you want more debugging information, you should enable the default logging, as described in the docs.

For now, I advise you to modify your VTN and VEN as follows:

#vtn.py

import asyncio
from openleadr import OpenADRServer, enable_default_logging

enable_default_logging()

...
#ven.py

import asyncio
from openleadr import OpenADRClient, enable_default_logging

enable_default_logging()

This wil now print the following information in your terminal after you start:

python vtn.py

********************************************************************************
                       Your VTN Server is now running at                        
                   http://127.0.0.1:8181/OpenADR2/Simple/2.0b                   
********************************************************************************

Responding to oadrCreatePartyRegistration with a oadrCreatedPartyRegistration message: {'ven_id': 'ven_id_123', 'registration_id': 'reg_id_123', 'profiles': [{'profile_name': '2.0b', 'transports': [{'transport_name': 'simpleHttp'}]}], 'requested_oadr_poll_freq': datetime.timedelta(seconds=10), 'vtn_id': 'myvtn', 'response': {'request_id': '5ee44e10-4547-4692-b517-5e37f2fd984e', 'response_code': 200, 'response_description': 'OK'}, 'request_id': 'a2a9f3ea-ec94-492e-bc17-91018138ed01'}.
Responding to oadrPoll with a oadrResponse message: {'vtn_id': 'myvtn', 'ven_id': 'ven_id_123', 'response': {'request_id': None, 'response_code': 200, 'response_description': 'OK'}, 'request_id': 'd87328f9-5dcc-420a-b60e-4195d3d90e00'}.
Responding to oadrPoll with a oadrResponse message: {'vtn_id': 'myvtn', 'ven_id': 'ven_id_123', 'response': {'request_id': None, 'response_code': 200, 'response_description': 'OK'}, 'request_id': 'fd22f696-8017-4139-8d8e-b9e3250b6dd0'}.
python ven.py
VEN is now registered with ID ven_id_123
The polling frequency is 0:00:10
arijeetr96 commented 3 years ago

Thanks, it works for me now. In the youtube video that you have shown, I am following the same steps but do you think that I supposed to more work on the code. and still, the server is shown on the website as code 404 error found. this is because no GUI is created yet? Is It? I need to create an event after successful registration, do I need any raspberry pie just like what you have done in the video?

stan-janssen commented 3 years ago

and still, the server is shown on the website as code 404 error found. this is because no GUI is created yet? Is It?

The server shows a URL that the VEN is supposed to connect to. It's what you enter as the vtn_url parameter in your VEN. It is not a website or GUI. In fact, the URL as shown does not exist, it is just a base URL that the OpenADRClient appends the service name to. So a full URL would be something like http://127.0.0.1:8181/OpenADR2/Simple/2.0b/oadrPoll, which only accepts POST requests. There is nothing you can do with a web browser in OpenADR. As I said in the first comment:

There is no GUI and OpenLEADR is not ready-to-run software. It is a Python package that allows you to build your own OpenADR clients and servers yourself.

About creating events:

I need to create an event after successful registration, do I need any raspberry pie just like what you have done in the video?

You don't need a Raspberry Pi to create an event. You can do it all in the same script that you are building. That script can be run on your Windows PC, on a Ubuntu PC, on a Raspberry Pi, whatever you want.

You still seem very confused about all the concepts that are in play to set this up. I really don't have time to guide you through every step.

The basic concept is this:

Please, please, PLEASE try to read some of the documentation that I prepared. I really made an effort to explain what you are supposed to do.

Arijeet96 commented 3 years ago

Thank you so much for guiding me. see I am a learner, so I am trying to do every step but I am not a good programmer where I can't understand everything which is posted in the manual/documentation. I am trying to follow the video and then documentation will try to complete all the steps. And for help, I don't think so except this site no one posted a single question on google.so I can't take any references. That's why I am asking questions when I am stuck somewhere in the code.

You don't need a Raspberry Pi to create an event. You can do it all in the same script that you are building. That script can be run on your Windows PC, on a Ubuntu PC, on a Raspberry Pi, whatever you want. In this line, I need to ask that if I am creating an event just like in the client-side I need to control any smart device of there's , no my windows can't do this thing, definitely we need microcontroller ESP or raspberry pie which can control the smart appliances same as what shown in the video.

I respect your time is important. Thanks.