Browse Source

iota

master
wenlele 12 months ago
parent
commit
28b2cd43bd
  1. 1
      api/.vscode/launch.json
  2. 59
      api/app/lib/controllers/bigScreen/index .js
  3. 52
      api/app/lib/routes/organization/index.js
  4. 8
      api/config.js
  5. 37
      web/client/src/sections/bigScreen/actions/bigScreen.js
  6. 40
      web/client/src/sections/bigScreen/components/electrity/realTimeStatus.js
  7. 2
      web/config.js

1
api/.vscode/launch.json

@ -17,6 +17,7 @@
//
"-g postgres://postgres:123456@10.8.30.166:5432/PumpStation",
// "-g postgres://FashionAdmin:123456@10.8.30.166:5432/PumpStation",
"-x http://221.230.55.28:7007", //
"--redisHost localhost",
"--redisPort 6379",
//

59
api/app/lib/controllers/bigScreen/index .js

@ -116,10 +116,65 @@ const getVideoUrl = async function (ctx) {
}
async function getDevices (ctx, next) {
try {
let { thingId } = ctx.query;
const res = await ctx.app.fs.iota.get(`/metrics/things/${thingId}/devices/link_status`) || {}
ctx.status = 200;
ctx.body = res.body;
} catch (err) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`);
ctx.status = 400;
ctx.body = { name: 'FindError', message: '获取iota数据失败' };
}
}
async function getInstances (ctx, next) {
try {
let { thingId } = ctx.query;
const res = await ctx.app.fs.iota.get(`/things/${thingId}/deploys`) || {}
ctx.status = 200;
ctx.body = res.body;
} catch (err) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`);
ctx.status = 400;
ctx.body = { name: 'FindError', message: '获取iota数据失败' };
}
}
async function getCapabilitiesInvoke (ctx, next) {
try {
let data = ctx.query;
const res = await ctx.app.fs.iota.post(`/capabilities/invoke`, data) || {}
ctx.status = 200;
ctx.body = res.body;
} catch (err) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`);
ctx.status = 400;
ctx.body = { name: 'FindError', message: '下发指令失败' };
}
}
module.exports = {
axyData,
pumpInformation,
getPumpStation,
getVideoUrl
getVideoUrl,
getDevices,
getInstances,
getCapabilitiesInvoke
}

52
api/app/lib/routes/organization/index.js

@ -6,39 +6,47 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/pump/station'] = { content: '获取所有站点信息', visible: true };
router.get('/pump/station', data.getPumpStation);
app.fs.api.logAttr['GET/pump/station'] = { content: '获取所有站点信息', visible: true };
router.get('/pump/station', data.getPumpStation);
app.fs.api.logAttr['POST/axyData'] = { content: '获取安心云数据', visible: true };
router.post('/axyData', data.axyData);
app.fs.api.logAttr['POST/axyData'] = { content: '获取安心云数据', visible: true };
router.post('/axyData', data.axyData);
app.fs.api.logAttr['GET/pumpInformation'] = { content: '获取泵站信息', visible: true };
router.get('/pumpInformation', data.pumpInformation);
app.fs.api.logAttr['GET/pumpInformation'] = { content: '获取泵站信息', visible: true };
router.get('/pumpInformation', data.pumpInformation);
app.fs.api.logAttr['GET/videoUrl'] = { content: '获取视频监控url', visible: true };
router.get('/videoUrl', data.getVideoUrl);
app.fs.api.logAttr['GET/videoUrl'] = { content: '获取视频监控url', visible: true };
router.get('/videoUrl', data.getVideoUrl);
app.fs.api.logAttr['GET/water/level/all'] = { content: '获取所有泵站七天内最新集水池液位', visible: true };
router.get('/water/level/all', data.getPumpStation);
app.fs.api.logAttr['GET/water/level/all'] = { content: '获取所有泵站七天内最新集水池液位', visible: true };
router.get('/water/level/all', data.getPumpStation);
app.fs.api.logAttr['GET/water/level/six'] = { content: '获取泵站6h最新集水池液位', visible: true };
router.get('/water/level/six', data.getPumpStation);
app.fs.api.logAttr['GET/water/level/six'] = { content: '获取泵站6h最新集水池液位', visible: true };
router.get('/water/level/six', data.getPumpStation);
app.fs.api.logAttr['GET/water/pump/state/all'] = { content: '获取水泵状态', visible: true };
router.get('/water/pump/state/all', data.getPumpStation);
app.fs.api.logAttr['GET/water/pump/state/all'] = { content: '获取水泵状态', visible: true };
router.get('/water/pump/state/all', data.getPumpStation);
app.fs.api.logAttr['GET/capacity'] = { content: '获取能耗监测数据', visible: true };
router.get('/capacity', data.getPumpStation);
app.fs.api.logAttr['GET/capacity'] = { content: '获取能耗监测数据', visible: true };
router.get('/capacity', data.getPumpStation);
app.fs.api.logAttr['GET/currentSix'] = { content: '获取水泵数据', visible: true };
router.get('/currentSix', data.getPumpStation);
app.fs.api.logAttr['GET/currentSix'] = { content: '获取水泵数据', visible: true };
router.get('/currentSix', data.getPumpStation);
app.fs.api.logAttr['GET/cabinet'] = { content: '获取进线柜数据', visible: true };
router.get('/cabinet', data.getPumpStation);
app.fs.api.logAttr['GET/cabinet'] = { content: '获取进线柜数据', visible: true };
router.get('/cabinet', data.getPumpStation);
app.fs.api.logAttr['GET/threePhase'] = { content: '获取三相电流数据', visible: true };
router.get('/threePhase', data.getPumpStation);
app.fs.api.logAttr['GET/threePhase'] = { content: '获取三相电流数据', visible: true };
router.get('/threePhase', data.getPumpStation);
app.fs.api.logAttr['GET/devices'] = { content: '获取水泵deviceId', visible: true };
router.get('/devices', data.getDevices);
app.fs.api.logAttr['GET/instances'] = { content: '获取水泵sensorId', visible: true };
router.get('/instances', data.getInstances);
app.fs.api.logAttr['GET/capabilities/invoke'] = { content: '下发指令', visible: true };
router.get('/capabilities/invoke', data.getCapabilitiesInvoke);
};

8
api/config.js

@ -17,6 +17,8 @@ args.option('redisPswd', 'redisPassword');
args.option('apiAnxinyunUrl', "安心云api");
args.option('axyProject', '安心云泵站项目信息');
args.option(['x', 'iota-proxy'], 'iota代理URL');
const flags = args.parse(process.argv);
@ -28,10 +30,11 @@ const AXY_BZ_PROJECT = process.env.AXY_BZ_PROJECT || flags.axyProject
const IOTA_REDIS_SERVER_HOST = process.env.IOTA_REDIS_SERVER_HOST || flags.redisHost || "localhost";//redis IP
const IOTA_REDIS_SERVER_PORT = process.env.IOTA_REDIS_SERVER_PORT || flags.redisPort || "6379";//redis 端口
const IOTA_REDIS_SERVER_PWD = process.env.IOTA_REDIS_SERVER_PWD || flags.redisPswd || "";//redis 密码
const ANXINCLOUD_PROXY_IOTA = process.env.ANXINCLOUD_PROXY_IOTA || flags.iotaProxy;
if (!BENGZHAN_DB || !API_ANXINYUN_URL || !AXY_BZ_PROJECT || !IOTA_REDIS_SERVER_HOST || !IOTA_REDIS_SERVER_PORT) {
if (!BENGZHAN_DB || !API_ANXINYUN_URL || !AXY_BZ_PROJECT || !IOTA_REDIS_SERVER_HOST || !IOTA_REDIS_SERVER_PORT || !ANXINCLOUD_PROXY_IOTA) {
console.log('缺少启动参数,异常退出');
args.showHelp();
process.exit(-1);
@ -63,6 +66,9 @@ const product = {
pssaRequest: [{// name 会作为一个 request 出现在 ctx.app.fs
name: 'anxinyun',
root: API_ANXINYUN_URL
}, {// name 会作为一个 request 出现在 ctx.app.fs
name: 'iota',
root: ANXINCLOUD_PROXY_IOTA
}],
}
}

37
web/client/src/sections/bigScreen/actions/bigScreen.js

@ -111,4 +111,41 @@ export function getThreePhase (query = {}) {
});
}
export function getDevices (query = {}) {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
actionType: 'GET_DEVICES',
url: 'devices',
query: query,
msg: { error: '获取水泵deviceId失败' },
reducer: { name: '' }
});
}
export function getInstances (query = {}) {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
actionType: 'GET_INSTANCES',
url: 'instances',
query: query,
msg: { error: '获取水泵sensorId失败' },
reducer: { name: '' }
});
}
export function getCapabilitiesInvoke (query = {}) {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
actionType: 'GET_CAPABILITIES_INVOKE',
url: 'capabilities/invoke',
query: query,
msg: { error: '下发指令失败' },
reducer: { name: '' }
});
}

40
web/client/src/sections/bigScreen/components/electrity/realTimeStatus.js

@ -110,12 +110,15 @@ const RealTimeStatus = ({ dispatch, actions, user, pumpId, pumpList, setPumpId,
let dimCapId = null;
const promiseArr = [
dispatch(bigScreen.axyData({
type: 'get', url: `/metrics/things/${thingId}/devices/link_status`
})),
dispatch(bigScreen.axyData({
type: 'get', url: `/things/${thingId}/devices/deploy`
}))
// dispatch(bigScreen.axyData({
// type: 'get', url: `/metrics/things/${thingId}/devices/link_status`
// })),
// dispatch(bigScreen.axyData({
// type: 'get', url: `/things/${thingId}/devices/deploy`
// }))
dispatch(bigScreen.getDevices({ thingId: thingId })),
dispatch(bigScreen.getInstances({ thingId: thingId }))
]
Promise.all(promiseArr).then(resArr => {
if (resArr[0].success && resArr[1].success) {
@ -135,21 +138,16 @@ const RealTimeStatus = ({ dispatch, actions, user, pumpId, pumpList, setPumpId,
break;
}
}
dispatch(bigScreen.axyData({
type: 'post', url: `/capabilities/invoke`,
params: {
data: {
thingId,
deviceId,
dimCapId,
timeout: 15000,
param: JSON.stringify({
id: sensorId,
order: label === '模式切换' ? 'mode' : label === '启动控制' ? 'run' : 'stop',
value: nextChecked.模式切换 ? 1 : 0 // 0:平台手动,1:启动泵/停止泵/平台液控)
})
}
}
dispatch(bigScreen.getCapabilitiesInvoke({
thingId,
deviceId,
dimCapId,
timeout: 15000,
param: JSON.stringify({
id: sensorId,
order: label === '模式切换' ? 'mode' : label === '启动控制' ? 'run' : 'stop',
value: nextChecked.模式切换 ? 1 : 0 // 0:平台手动,1:启动泵/停止泵/平台液控)
})
})).then(res => {
console.log('控制res', res)
})

2
web/config.js

@ -18,8 +18,8 @@ args.option(['u', 'api-url'], 'webapi的URL');
const flags = args.parse(process.argv);
const flags = args.parse(process.argv);
const FS_UNIAPP_API = process.env.FS_UNIAPP_API || flags.apiUrl;
const weatherUrl = process.env.ANXINCLOUD_WEATHERAPP_API || "https://weatherssj.anxinyun.cn/weatherApp/weather/getImmeData"

Loading…
Cancel
Save