# MyEMS API Service
## Introduction
Providing REST API service for [MyEMS](https://github.com/MyEMS/myems) components and third parties.
## Prerequisites
anytree
simplejson
mysql.connector
falcon
falcon_cors
gunicorn
openpyxl
## Installation
In this step, you will install myems-api on Ubuntu for production or development.
For macOS developers, please refer to [Installation on macOS (Chinese)](./installation_macos_zh.md)
* Install anytree
```bash
cd ~/tools
git clone https://github.com/c0fec0de/anytree.git
cd anytree
sudo python3 setup.py install
```
* Install simplejson
```bash
cd ~/tools
git clone https://github.com/simplejson/simplejson.git
cd simplejson
sudo python3 setup.py install
```
* Install MySQL Connector
```bash
cd ~/tools
wget https://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-8.0.20.tar.gz
tar xzf mysql-connector-python-8.0.20.tar.gz
cd ~/tools/mysql-connector-python-8.0.20
sudo python3 setup.py install
```
* Install Falcon,
if you are behind proxy, use --proxy parameter
Refer to
https://falconframework.org/
https://github.com/lwcolton/falcon-cors
https://github.com/yohanboniface/falcon-multipart
```bash
mkdir ~/tools/falcon && cd ~/tools/falcon
pip3 download cython falcon falcon-cors falcon-multipart
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales
sudo pip3 install --upgrade --no-index --find-links ~/tools/falcon cython falcon falcon-cors falcon-multipart
```
* Install gunicorn, refer to http://gunicorn.org
```bash
mkdir ~/tools/gunicorn && cd ~/tools/gunicorn
pip3 download gunicorn
sudo pip3 install --no-index --find-links ~/tools/gunicorn gunicorn
```
* Install openpyxl, refer to https://foss.heptapod.net/openpyxl/openpyxl
Get the latest version of et_xmlfile from https://foss.heptapod.net/openpyxl/et_xmlfile
Get the latest version of jdcal from https://github.com/phn/jdcal
Get the latest version of openpyxl from https://foss.heptapod.net/openpyxl/openpyxl
```bash
cd ~/tools
wget https://foss.heptapod.net/openpyxl/et_xmlfile/-/archive/branch/default/et_xmlfile-branch-default.tar.gz
tar xzf et_xmlfile-branch-default.tar.gz
cd ~/tools/et_xmlfile-branch-default
sudo python3 setup.py install
cd ~/tools
git clone https://github.com/phn/jdcal.git
cd ~/tools/jdcal
sudo python3 setup.py install
mkdir ~/tools/pillow && cd ~/tools/pillow
pip3 download Pillow
sudo pip3 install --no-index --find-links ~/tools/pillow Pillow
cd ~/tools
wget https://foss.heptapod.net/openpyxl/openpyxl/-/archive/branch/3.0/openpyxl-branch-3.0.tar.gz
tar xzf openpyxl-branch-3.0.tar.gz
cd openpyxl-branch-3.0
sudo python3 setup.py install
```
* Download myems:
```bash
cd ~
git clone https://github.com/MyEMS/myems.git
```
* Install gunicorn service for myems-api:
```bash
cd ~/myems/myems-api
sudo cp -R ~/myems/myems-api /myems-api
```
Change the config file:
Note: change cookie domain to the actual domain or IP address of Web UI and Admin UI
```bash
sudo nano /myems-api/config.py
```
Change the listening port (default is 8000) in gunicorn.socket:
```bash
sudo nano /myems-api/myems-api.socket
```
```bash
ListenStream=0.0.0.0:8000
```
```bash
sudo ufw allow 8000
```
Setup systemd configure files:
```bash
sudo cp /myems-api/myems-api.service /lib/systemd/system/
sudo cp /myems-api/myems-api.socket /lib/systemd/system/
sudo cp /myems-api/myems-api.conf /usr/lib/tmpfiles.d/
```
Next enable the services so that they autostart at boot:
```bash
sudo systemctl enable myems-api.socket
sudo systemctl enable myems-api.service
```
Start the services :
```bash
sudo systemctl start myems-api.socket
sudo systemctl start myems-api.service
```
## Run for debugging and testing
```bash
cd myems-api
sudo gunicorn -b 127.0.0.1:8000 app:api
```
## API List
View in Postman: import the file MyEMS.postman_collection.json with Postman
[Energy Category](#Energy-Category) | [Energy Item](#Energy-Item)
[Data Source](#Data-Source) | [Point](#Point)
[Tariff](#Tariff) | [Cost Center](#Cost-Center) | [Cost File](#Cost-File)
[Meter](#Meter) | [Virtual Meter](#Virtual-Meter) | [Offline Meter](#Offline-Meter) | [Offline Meter File](#Offline-Meter-File)
[Space](#Space) | [Tenant](#Tenant) | [Tenant Type](#Tenant-Type) | [Store](#Store) | [Store Type](#Store-Type) | [Shopfloor](#Shopfloor)
[Equipment](#Equipment) | [Combined Equipment](#Combined-Equipment)
[Energy Flow Diagram](#Energy-Flow-Diagram)
[Distribution System](#Distribution-System) | [Distribution Circuit](#Distribution-Circuit)
[Rule](#Rule) | [Email Message](#Email Message) | [Text Message](#Text Message) | [Web Message](#Web Message) | [Wechat Message](#Wechat Message)
[Email Server](#Email Server) | [GSM Modem](#GSM Modem)
[User](#User) | [Privilege](#Privilege) | [Contact](#Contact) | [Notification](#Notification)
[Timezone](#Timezone)
[Menu](#Menu)
[Knowledge File](#Knowledge-File)
[Reports](#Reports)
### Contact
* GET Contact by ID
```bash
curl -i -X GET {{base_url}}/contacts/{id}
```
* GET All Contacts
```bash
curl -i -X GET {{base_url}}/contacts
```
* DELETE Contact by ID
```bash
curl -i -X DELETE {{base_url}}/contacts/{id}
```
* POST Create a New Contact
```bash
curl -i -H "Content-Type: application/json" -X POST -d '{"data":{"name":"albert", "email":"albert@myems.io", "phone":"+8613888888888", "description":"contact description"}}' {{base_url}}/contacts
```
* PUT Update a Contact
```bash
curl -i -H "Content-Type: application/json" -X PUT -d '{"data":{"name":"albert", "email":"albert@myems.io", "phone":"+8613888888899", "description":"contact description"}}' {{base_url}}/contacts/{id}
```
### Cost Center
* GET Cost Center by ID
```bash
curl -i -X GET {{base_url}}/costcenters/{id}
```
Result in JSON
| Name | Data Type | Description |
|---------------|-----------|-------------------------------------------|
| id | integer | Cost Center ID |
| name | string | Cost Center name |
| uuid | string | Cost Center UUID |
| external_id | string | Cost Center External ID ( For example, ID in SAP, ERP...) |
* GET all Cost Centers
```bash
curl -i -X GET {{base_url}}/costcenters
```
* DELETE Cost Center by ID
```bash
curl -i -X DELETE {{base_url}}/costcenters/{id}
```
* POST Create New Cost Center
```bash
curl -i -H "Content-Type: application/json" -X POST -d '{"data":{"name":"动力中心", "external_id":"21829198980001"}}' {{base_url}}/costcenters
```
* PUT Update a Cost Center
```bash
curl -i -H "Content-Type: application/json" -X PUT -d '{"data":{"name":"动力中心2", "external_id":"21829198980002"}}' {{base_url}}/costcenters/{id}
```
* GET All Tariffs associated with Cost Center ID
```bash
curl -i -X GET {{base_url}}/costcenters/{id}/tariffs
```
* POST Create a Cost Center and Tariff Relation
```bash
curl -i -H "Content-Type: application/json" -X POST -d '{"data":{"tariff_id":"3"}}' {{base_url}}/costcenters/{id}/tariffs
```
* DELETE a Cost Center and Tariff Relation by tid
```bash
curl -i -X DELETE {{base_url}}/costcenters/{id}/tariffs/{tid}
```
### Cost File
* GET an Cost File by ID
```bash
curl -i -X GET {{base_url}}/costfiles/{id}
```
Result
| Name | Data Type | Description |
|---------------|-----------|-------------------------------------------|
| id | integer | Cost File ID |
| file_name | string | Cost File name |
| uuid | string | Cost File UUID |
| upload_datetime | float | the number of milliseconds since January 1, 1970, 00:00:00, universal time |
| status | string | Cost File processing status (new, done, error) |
| file_object | BLOB | Cost File Object |
* GET All Cost
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
MyEMS是行业领先的开源能源管理系统。可用于能源管理项目的设备管理、数据采集、处理、分析、可视化和报表。MyEMS由资深专业团队开发维护,系统代码基于MIT开源软件许可协议发布。用开源助力实现碳达峰碳中和 https://myems.io https://gitee.com/myems/myems https://github.com/myems/myems
资源详情
资源评论
资源推荐
收起资源包目录
MyEMS能源管理系统v1.2.3 (3561个子文件)
make.bat 795B
.browserslistrc 81B
CNAME 8B
nginx.conf 1KB
nginx.conf 1KB
myems-api.conf 33B
theme-dark-rtl.css 397KB
theme-dark.css 397KB
theme-rtl.css 382KB
theme.css 382KB
style.css 169KB
bootstrap.css 143KB
bootstrap.min.css 118KB
animate.css 64KB
bootstrap-rtl.css 31KB
style.css 29KB
font-awesome.css 28KB
style.min.css 25KB
bootstrap-rtl.min.css 24KB
font-awesome.min.css 23KB
fonts-swap.css 19KB
fonts.css 19KB
sweetalert.css 18KB
colorpicker.css 17KB
chartist.min.css 14KB
jasny-bootstrap.min.css 14KB
myems.css 13KB
chosen.css 13KB
social-buttons.css 13KB
dropzone.css 12KB
fullcalendar.css 11KB
toastr.min.css 11KB
datatables.min.css 10KB
integralui.css 8KB
ladda-themeless.min.css 8KB
angular-datapicker.css 7KB
blueimp-gallery.min.css 7KB
daterangepicker-bs3.css 7KB
awesome-bootstrap-checkbox.css 7KB
select.min.css 6KB
blueimp-gallery.css 6KB
daterangepicker.min.css 6KB
jquery.steps.css 6KB
footable.core.css 5KB
fullcalendar.print.css 5KB
tree-icon.css 4KB
clockpicker.css 4KB
ng-dropzone.css 4KB
integralui.treeview.css 3KB
ion.rangeSlider.css 3KB
slick-theme.css 3KB
jquery.nouislider.css 3KB
loading-bar.css 3KB
bootstrap-markdown.min.css 3KB
blueimp-gallery-video.css 2KB
bootstrap-tour.min.css 2KB
theme-bootstrap.css 2KB
ion.rangeSlider.skinFlat.css 2KB
jquery.justifiedgallery.css 2KB
slick.css 2KB
ion.rangeSlider.skinSimple.css 2KB
ion.rangeSlider.skinNice.css 2KB
blueimp-gallery-indicator.css 2KB
jquery.justifiedgallery.min.css 1KB
angular-notify.min.css 1KB
custom.css 1KB
angular-ui-tree.min.css 1KB
basic.css 1KB
integralui.checkbox.css 1KB
jquery.bootstrap-touchspin.min.css 899B
demo.css 867B
switchery.css 610B
angular-csp.css 343B
flyout.css 205B
ng-img-crop.css 195B
jquery-jvectormap-2.0.2.css 0B
Dockerfile 373B
Dockerfile 310B
Dockerfile 216B
Dockerfile 183B
Dockerfile 183B
Dockerfile 183B
Dockerfile 183B
.editorconfig 413B
.editorconfig 413B
fontawesome-webfont.eot 59KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
footable.eot 5KB
slick.eot 2KB
myems-space-energycategory2.gif 3.98MB
myems-large-screen-dashboard.gif 2.11MB
myems-space-energycategory3.gif 1.25MB
myems-space-energycategory1.gif 345KB
loading.gif 9KB
ajax-loader.gif 4KB
loading.gif 4KB
throbber.gif 2KB
.gitattributes 111B
.gitignore 4KB
共 3561 条
- 1
- 2
- 3
- 4
- 5
- 6
- 36
MyEMS
- 粉丝: 3
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1