Commit 5f03ddad by Aeolus

修改onenet为全国平台+江苏平台

parent 8f178132
......@@ -2,11 +2,21 @@
import os
is_prod = os.getenv("RUN_ENV", "test") == 'prod'
ONENET_CONFIG = {
"encoding_AES_key": "XzHtYS3PbRiCDErEaztV286Cf4QmmL21T77tEY4Yb2m",
"he_cloud_token": "suishenwanonenettesttokenhecloud",
"url": 'http://api.js.cmcconenet.com',
}
NEW_ONENET_CONFIG = {
"encoding_AES_key": "XzHtYS3PbRiCDErEaztV286Cf4QmmL21T77tEY4Yb2m",
"he_cloud_token": "suishenwanonenettesttokenhecloud",
"url": "http://api.heclouds.com",
"api_key": "tu61pm=W3WgckJWqwiokfc066iA=" if is_prod else 'MYbymxp2GNuEQ95RRulstC4duwo=',
"he_cloud_device_id": ["617584147"]
}
if is_prod:
ONENET_CONFIG['api_key'] = "aFpHq1TkvggQrHkTgMlTKA2pXAI="
else:
......
......@@ -10,6 +10,7 @@ from Model.Base import db
from Model.Machine.MachineModel import Machine
from Model.Power.PowerModel import Power
from Service.ToolService import ToolService
from Config.common_config import NEW_ONENET_CONFIG as new_onenet_config, ONENET_CONFIG as onenet_config
route_tool = Blueprint('tool', __name__)
......@@ -50,8 +51,10 @@ def take_out():
return jsonify(MACHINE_NOT_ONLINE)
command_message = CommandMessage(machine_info.he_cloud_device_id, chr(0x46), str(hatch_no - 1))
one_api = OneNetApi()
if machine_info.he_cloud_device_id in new_onenet_config["he_cloud_device_id"]:
one_api = OneNetApi(new_onenet_config["api_key"], new_onenet_config["url"])
else:
one_api = OneNetApi(onenet_config["api_key"], onenet_config["url"])
result = one_api.send_data_to_edp(command_message.get_device_id(), 1, 0, command_message.pack())
if "errno" in result.keys() and result['errno'] == 0:
if result['error'] == 'succ':
......@@ -82,7 +85,10 @@ def take_out_multiple():
data = {}
for i in hatch_no_list:
command_message = CommandMessage(machine_info.he_cloud_device_id, chr(0x46), str(i - 1))
one_api = OneNetApi()
if machine_info.he_cloud_device_id in new_onenet_config["he_cloud_device_id"]:
one_api = OneNetApi(new_onenet_config["api_key"], new_onenet_config["url"])
else:
one_api = OneNetApi(onenet_config["api_key"], onenet_config["url"])
result = one_api.send_data_to_edp(command_message.get_device_id(), 1, 0, command_message.pack())
if 'errno' in result.keys() and result['errno'] == 0:
if result['error'] == 'succ':
......
......@@ -2,13 +2,17 @@
from Libs.Onenet.Message.Message import CommandMessage
from Libs.Onenet.OneNetApi import OneNetApi
from Config.common_config import NEW_ONENET_CONFIG as new_onenet_config, ONENET_CONFIG as onenet_config
class OneNet(object):
@staticmethod
def open(machine, position):
command_message = CommandMessage(machine.he_cloud_device_id, chr(0x46), str(position - 1))
one_api = OneNetApi()
if machine.he_cloud_device_id in new_onenet_config["he_cloud_device_id"]:
one_api = OneNetApi(new_onenet_config["api_key"], new_onenet_config["url"])
else:
one_api = OneNetApi(onenet_config["api_key"], onenet_config["url"])
result = one_api.send_data_to_edp(command_message.get_device_id(), 1, 0, command_message.pack())
if not result or result.get("error", None) is not None:
return False
......
......@@ -10,7 +10,7 @@ from Config.common_config import ONENET_CONFIG as config, LIUYUAN_CONFIG
class OneNetApi(object):
_key = None
_base_url = 'http://api.heclouds.com'
_base_url = None
_raw_response = ''
_http_code = 200
_error_no = 0
......@@ -19,7 +19,6 @@ class OneNetApi(object):
def __init__(self, key=None, base_url=None):
self._key = key
if base_url:
self._base_url = base_url
def get_raw_response(self):
......@@ -35,7 +34,7 @@ class OneNetApi(object):
return self._http_code
def get_cur_api_key(self):
return config["api_key"]
return self._key
def get_liuyuan_api_key(self):
return LIUYUAN_CONFIG
......@@ -400,7 +399,7 @@ class OneNetApi(object):
if url[0] != '/':
url = '/' + url
return config["url"] + url
return self._base_url + url
def _beforeCall(self, ch, url, method, data):
pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment