Ana içeriğe geç

ViewPLUS SCADA Web API

Tanıtım

ViewPLUS SCADA Node WebAPI kullanarak sahadaki cihazlara erişebilir ve kontrol edebilirsiniz.

Aşağıdaki bağlantıdan ViewPLUS SCADA Node WebAPI'yi indirin:

SCADA Node Web API

Veritabanı Bağlantısı

Projenin üzerinde çalıştığı veritabanı tipi HR_DBTYPE çevre değişkeni ile belirtilmelidir (POSTGRES / ORACLE) Postgresql veritabanındaki bir proje için, HR_PGCONNECTIONSTRING çevresel değişkeni aşağıdaki örnekte verilen biçimde ayarlanmalıdır. Oracle veritabanı üzerinde bir proje için HR_CONNECTIONSTRING, HR_USER ve HR_PASSWORD çevresel değişkenleri aşağıdaki formatta ayarlanmalıdır.

scada-webapi-01

Sunucuyu Başlatma

  • Install node.js
  • Install dependencies: Uygulama klasörüne "npm install" yazın
  • Set enviromental variables for: HR_DBTYPE : POSTGRES or ORACLE HR_CONNECTIONSTRING : Oracle DB connection string(example : 127.0.0.1/orcl) HR_PGCONNECTIONSTRING : Example postgres://postgres:[email protected]:5432/scadatest1 (example; user: postgres, pwd: qwx123, server: 127.0.0.1, port: 5432, project: scadatest1) HR_USER : Oracle DB user name for project( It is SCADA project name) HR_PASSWORD : Oracle DB password
  • Configure web server port if needed on the file ".\config\web-server.js" (default 3000)
  • Change application secret for JWT on ./config.js
  • Start server by typing "node ."

Erişim belirteci almak için

SCADA'da yeni bir kullanıcı oluşturulur. Kullanıcı "Raporlara Erişebilir" yetkisine sahip olmalıdır. Gövde içinde, "username" ve "password" tuşlarıyla http://localhost:3000/api/auth/login adresine bir POST sorgusu gönderilir. Bir jeton aşağıdaki gibi alınır:

{
"auth": true,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNTM3MzU5MDc1LCJ leHAiOjE1Mzc0NDU0NzV9.NX5kX4HLVdE4IoPcSBWkdlGKK_pksHnTnEoWCx1xCyc"
}

http://localhost:3000 örnek olarak verilmiştir. Bunu gerçek sistemin IP ve Bağlantı Noktası bilgileriyle değiştirin.

API'den veri okumak için

Bu belirteç başlıktaki "x-access-token" anahtar değerine eklenerek aşağıdaki GET istekleri gönderilebilir:

  • Information of all tags defined in the system
http://localhost:3000/api/auth/tags   or http://localhost:3000/api/auth/tags/{id}
Sample Result:
[
{
"id": 1,
"tagname": "tag1",
"kanal_id": 1,
"polfreq": 3,
"deviceaddress": "1",
"variableaddress": "0",
"variablesize": 4,
"variabletype": 2,
"islogging": 0,
"privilegelevel": 0,
"tagtype": 0,
"schedulerindex": 0,
"loggingfreq": 300,
"loggingmethod": 6619250,
"readright1": 0,
"readright2": 0,
"writeright1": 0,
"writeright2": 0,
"keywords": null,
"enabled": 1,
"description": null,
"unitname": null,
"protocolobjecttype": 0,
"toption": 0,
"logfilteroptions": "{\n \"filtertype\": 0,\n \"refval1\": null,\n \"refval2\": null\n}\n",
"equipment": null,
"measuredentity": null,
"location": null,
"formula": null,
"modified": 0
},

]
  • Information of all alarms that defined in the system
http://localhost:3000/api/auth/alarms  or http://localhost:3000/api/auth/alarms/{id}

Sample Result:
[
{
"id": 1,
"alarm_name": "Alarm1",
"alarm_desc": "NoDescription",
"alarm_class": "General",
"enabled": 1,
"ackrequired": 0,
"islogging": 0,
"tag_id": 3,
"alarm_type": 0,
"alarm_level": 0,
"comp_type": 1
},

]

By using the "tag_id" value in this scheme, information about the tag that causes the alarm can be accessed from "api / auth / tags".
  • List of alarms that are instantly active in the system:
http://localhost:3000/api/auth/active_alarms or http://localhost:3000/api/auth/active_alarms/{id}

Sample Result:
[
{
"id": 4,
"alarm_id": 1,
"user_name": null,
"dataval": 1,
"currentstate": 1,
"trigertime": 1537229311140,
"acktime": -1,
"recovtime": -1,
"logtime": 1537229311140,
"logdate": null,
"mailsent": 0,
"ackmessage": null
},

]

The details of the alarm can be accessed from "api / auth / alarms" by using the "alarm_id" value in this scheme.
  • Information of all channels defined in the system
http://localhost:3000/api/auth/channels  or http://localhost:3000/api/auth/channels/{id}

Sample Result:
[
{
"id": 1,
"channelname": "Channel1",
"mediatype_id": 0,
"sockettype_id": 0,
"paritytype_id": 0,
"protocoltype_id": 0,
"serverport": 1080,
"listenport": 1081,
"serverip": "127.0.0.1",
"filterip": "0.0.0.0",
"comport": 11,
"baudrate": 115200,
"databit": 8,
"stopbit": 1,
"responseto": 6000,
"connectionto": 6000,
"frameto": 3000,
"groupid": -1,
"station": null,
"enabled": 1,
"logicpropath": null,
"description": null,
"modified": 0,
"state": null
},

]
  • Instantaneous values of labels defined in the system
http://localhost:3000/api/auth/rt_values or http://localhost:3000/api/auth/rt_values/{id}

Sample Result:
[
{
"id": 1,
"tag_id": 3,
"dataval": 1,
"logtime": 1537229310000,
"logdate": "2018-09-18T00:08:30.000Z"
},

]
  • Updating the tag value in the system

localhost:3000/api/auth/write_buffer

scada-webapi-02

scada-webapi-03