140 Star 907 Fork 342

MyEMS / MyEMS能源管理系统

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 4.84 KB
一键复制 编辑 原始数据 按行查看 历史
张能远 提交于 2023-05-22 13:40 . added microgrid actions in myems-api

MyEMS API Service

Introduction

RESTful API service for MyEMS components and third party applications.

Dependencies

anytree

simplejson

mysql-connector-python

falcon

falcon_cors

falcon-multipart

gunicorn

et_xmlfile

jdcal

openpyxl

pillow

python-decouple

Quick Run for Development

Quick run on Linux (NOT for production use):

cd myems/myems-api
sudo pip install -r requirements.txt
cp example.env .env
sudo chmod +x run.sh
./run.sh

Quick run on Windows (NOT for production usage):

Find python path in Command Prompt:

where python

Assume the result is 'C:\Users\johnson\AppData\Local\Programs\Python\Python310\python.exe'

Copy fcntl.py and pwd.py to lib folder:

cp myems\myems-api\fcntl.py C:\Users\johnson\AppData\Local\Programs\Python\Python310\Lib
cp myems\myems-api\pwd.py C:\Users\johnson\AppData\Local\Programs\Python\Python310\Lib

Install and run with waitress:

pip install waitress
cd myems\myems-api
waitress-serve --listen=0.0.0.0:8000 app:api

Installation

Installation Option 1: Install myems-api on Docker

Refer to myems.io

Option 2: Online install myems-api on Ubuntu Server with internet access

Refer to myems.io

Option 3: Offline install myems-api on Ubuntu Server without internet access

In this section, you will offline install myems-api on Ubuntu Server without internet access.

  • Download tools
mkdir ~tools && cd ~/tools
git clone https://github.com/c0fec0de/anytree.git
git clone https://github.com/simplejson/simplejson.git
wget https://cdn.mysql.com//Downloads/Connector-Python/mysql-connector-python-8.0.28.tar.gz
mkdir ~/tools/falcon && cd ~/tools/falcon
pip download cython falcon falcon-cors falcon-multipart
cd ~/tools
mkdir ~/tools/gunicorn && cd ~/tools/gunicorn
pip download gunicorn
cd ~/tools
wget https://foss.heptapod.net/openpyxl/et_xmlfile/-/archive/1.1/et_xmlfile-1.1.tar.gz
cd ~/tools
git clone https://github.com/phn/jdcal.git
mkdir ~/tools/pillow && cd ~/tools/pillow 
pip download Pillow
cd ~/tools
wget https://foss.heptapod.net/openpyxl/openpyxl/-/archive/3.0.7/openpyxl-3.0.7.tar.gz
cd ~/tools
git clone https://github.com/henriquebastos/python-decouple.git
  • Copy source code and tools to the production Ubuntu Server and then run:
cd ~/tools/anytree
python setup.py install 
cd ~/tools/simplejson
python setup.py install 
cd ~/tools
tar xzf mysql-connector-python-8.0.28.tar.gz
cd ~/tools/mysql-connector-python-8.0.28
python setup.py install
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
dpkg-reconfigure locales
pip install --upgrade --no-index --find-links ~/tools/falcon cython falcon falcon-cors falcon-multipart
pip install --no-index --find-links ~/tools/gunicorn gunicorn
cd ~/tools
tar xzf et_xmlfile-1.1.tar.gz
cd ~/tools/et_xmlfile-1.1
python setup.py install
cd ~/tools/jdcal
python setup.py install
cd ~/tools
pip install --no-index --find-links ~/tools/pillow Pillow
tar xzf openpyxl-3.0.7.tar.gz
cd ~/tools/openpyxl-3.0.7
python setup.py install
cd ~/tools/python-decouple
python setup.py install
  • Install myems-api service:
cp -r myems/myems-api /myems-api

Create .env file based on example.env and edit the .env file if needed:

cp /myems-api/example.env /myems-api/.env
nano /myems-api/.env

Check or change the listening port (default is 8000) in myems-api.service and myems-api.socket:

nano /myems-api/myems-api.service
ExecStart=/usr/local/bin/gunicorn -b 0.0.0.0:8000 --pid /run/myems-api/pid --timeout 600 --workers=4 app:api
nano /myems-api/myems-api.socket
ListenStream=0.0.0.0:8000

Add port to firewall:

ufw allow 8000

Setup systemd configure files:

cp /myems-api/myems-api.service /lib/systemd/system/
cp /myems-api/myems-api.socket /lib/systemd/system/
cp /myems-api/myems-api.conf /usr/lib/tmpfiles.d/

Next enable the services so that they autostart at boot:

  systemctl enable myems-api.socket
  systemctl enable myems-api.service

Start the services :

systemctl start myems-api.socket
systemctl start myems-api.service

Installation Option 4: Install myems-api on macOS

Refer to Installation on macOS (Chinese)

API List

Please refer to API List

References

[1]. http://myems.io

[2]. https://falconframework.org/

[3]. https://github.com/lwcolton/falcon-cors

[4]. https://github.com/yohanboniface/falcon-multipart

[5]. http://gunicorn.org

[6]. https://github.com/henriquebastos/python-decouple/

[7]. https://foss.heptapod.net/openpyxl/openpyxl

[8]. https://foss.heptapod.net/openpyxl/et_xmlfile/

[9]. https://docs.pylonsproject.org/projects/waitress/en/latest/

Python
1
https://gitee.com/myems/myems.git
git@gitee.com:myems/myems.git
myems
myems
MyEMS能源管理系统
master

搜索帮助