Forum Home › Forums › Development and Integration › REST API for the RapidScada
Tagged: permission, REST API, Version 6.1
- This topic has 9 replies, 3 voices, and was last updated 2 weeks, 4 days ago by
heavenbird.
-
AuthorPosts
-
April 16, 2023 at 1:54 am #12442
tgkim79
ParticipantI have to connect and get data and send commands to Rapid SCADA through the Mobile App developed by Dart language.
so as I know the V6.1 supports the REST API for the interface with the external device. I tried and I had success in login (using /Api/Auth/Login).
however, I had failed to get data(using /Api/Main/GetCurData) the statusCode is 401. I couldn’t find any information on the web or article. so what should I do to solve it?April 16, 2023 at 8:09 am #12449Mikhail
ModeratorHello,
To solve the issue, try handling cookies. Please check this example.
April 16, 2023 at 8:12 am #12450Mikhail
ModeratorBy the way, could you share info about your application? Is it web or mobile?
April 16, 2023 at 8:27 am #12451tgkim79
Participantit’s mobile
April 16, 2023 at 11:19 am #12452tgkim79
ParticipantI solve the problem.
I share the dart code. I will be glad if someone will modify it to a better code.import 'package:dio_cookie_manager/dio_cookie_manager.dart'; import 'package:flutter/foundation.dart'; import 'package:cookie_jar/cookie_jar.dart'; import 'package:dio/dio.dart'; class InterfaceApi{ InterfaceApi(); late CookieJar cookies; late Dio dio; static var webSvrUrl = "http://192.168.35.145:10008"; Future<void> writeResponse(Response response) async{ final responseString = response.data.toString(); if(responseString.isNotEmpty){ if (kDebugMode) { print("RESULT[$responseString]"); } } } Future<bool> webSvrLogin() async{ bool result = false; cookies = CookieJar(); dio = Dio(BaseOptions(baseUrl: webSvrUrl,responseType: ResponseType.json)) ..interceptors.add(CookieManager(cookies)); var loginResponse = await dio.post( '$webSvrUrl/Api/Auth/Login', data: { 'username': "admin", 'password': "12345"}, ); if(loginResponse.statusCode == 200){ var loginResult = LoginResult.fromJson(loginResponse.data); result = loginResult.status; if (!result) { if (kDebugMode) { print('Result [${loginResult.msg}]'); } result = false; } }else{ if (kDebugMode) { print('Status Code :[${loginResponse.statusCode}]'); } result = false; } return result; } Future<dynamic> webSvrReadSingleData(int tagId) async{ var requestData = await dio.get("$webSvrUrl/Api/Main/GetCurData?cnlNums=$tagId"); await writeResponse(requestData); } Future<bool> webSvrWriteSingleData(int tagId, double value) async{ bool result = true; var response = await dio.post( "$webSvrUrl/Api/Main/SendCommand", data:{ "cnlNum":"$tagId", "cmdVal":"$value" } ); if(response.statusCode == 200){ result = true; }else{ result = false; } return result; } } class LoginResult { late bool status; late String msg; LoginResult({required this.status, required this.msg}); factory LoginResult.fromJson(Map<String, dynamic> json) { return LoginResult( status: json["ok"] as bool, msg: json["msg"] as String, ); } }
-
This reply was modified 1 month, 3 weeks ago by
Mikhail.
April 17, 2023 at 1:02 pm #12454Mikhail
ModeratorThank you for the code.
If you publish your application to Google Play, please let us know.May 22, 2023 at 5:37 am #12664heavenbird
ParticipantThank you @Mikhail @tgkim79.
I have already used NodeRED’s http method to obtain data from RapidSCADA.
The access format is http://192.168.20.122/Api/Main/GetCurData?cnlNums=201-208.
But his use of numbers is not very intuitive, and I need to establish a correspondence between numbers and names.Can I obtain data using names? For example, how can I obtain the data of channel by using http://192.168.20.122/Api/Main/GetCurData?cnlNames=kep – _System._Time_Second?
-
This reply was modified 2 weeks, 4 days ago by
heavenbird.
-
This reply was modified 2 weeks, 4 days ago by
heavenbird.
May 22, 2023 at 5:54 am #12667tgkim79
ParticipantWhen I checked the source code from the Rapid Scada, the GetCurData API had no parameter for colNames. (am I right? TT;)
so.. I think if you want to use colNames, you have to create a function for finding cnlNumber by Name.
In my case, my app loaded all databases that contain all cnl numbers and each tag name and I created a function for searching from that database cnlnumber by tagname.May 22, 2023 at 7:41 am #12673Mikhail
ModeratorHello,
API provides access to channel data by channel numbers. Channel names are not unique, so cannot be used to get data.Getting channel data using REST API by some unique string codes can be a good idea for the future improvements. Currently, you need an internal dictionary that provides channel number by its name or code.
May 22, 2023 at 1:02 pm #12677heavenbird
Participant -
This reply was modified 1 month, 3 weeks ago by
-
AuthorPosts
- You must be logged in to reply to this topic.