REST API for the RapidScada

Forum Home Forums Development and Integration REST API for the RapidScada

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #12442
    tgkim79
    Participant

    I 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?

    #12449
    Mikhail
    Moderator

    Hello,

    To solve the issue, try handling cookies. Please check this example.

    #12450
    Mikhail
    Moderator

    By the way, could you share info about your application? Is it web or mobile?

    #12451
    tgkim79
    Participant

    it’s mobile

    #12452
    tgkim79
    Participant

    I 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 year ago by Mikhail.
    #12454
    Mikhail
    Moderator

    Thank you for the code.
    If you publish your application to Google Play, please let us know.

    #12664
    heavenbird
    Participant

    Thank 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 11 months ago by heavenbird.
    • This reply was modified 11 months ago by heavenbird.
    #12667
    tgkim79
    Participant

    When 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.

    #12673
    Mikhail
    Moderator

    Hello,
    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.

    #12677
    heavenbird
    Participant

    Thank you very much for your prompt reply! @Mikhail @tgkim79

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.