自动刷新Justgage中的值机器学习数据仪表板

问题描述 投票:0回答:2
javascript html ajax setinterval justgage
2个回答
0
投票

刷新仪表的最佳方法是使用 FCM (firebase)。

https://firebase.google.com/docs/cloud-messaging?hl=pt-br

在每次更改中,您都不会向 Firebase 发送通知,当返回响应 Firebase 时,您会调用该函数。

如果您使用 PHP,您可以使用curl 发送通知。喜欢:

public function sendNotification($title, $body, $token)
 {
    $url = 'https://fcm.googleapis.com/fcm/send';
    $headers = [
        'Authorization: key=GET_THE_AUTORIZATION_AND_PUT_HERE',
        'Content-type: application/json'
    ];
    $notification = [
        'title' => $title,
        'body'  => $body
    ];

    $request = [
        'notification' => $notification,
        "registration_ids" => array($token)
    ];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request));

    $res = curl_exec($ch);
    return $res;

    curl_close($ch);
 }

在 Firebase 中注册后,您将获取信息并输入代码 js。应该是这样的:

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
    apiKey: "this information is filled by firebase",
    authDomain: "this information is filled by firebase",
    projectId: "this information is filled by firebase",
    storageBucket: "this information is filled by firebase",
    messagingSenderId: "this information is filled by firebase",
    appId: "this information is filled by firebase",
    measurementId: "this information is filled by firebase"
};
 // Initialize Firebase
 firebase.initializeApp(firebaseConfig);

 let token;
 const fcm = firebase.messaging();
 fcm.getToken({
 vapidkey: 'IN HERE YOU PUT KEY PAIR' // yout get in settings > cloudmessaging - in the firebase
 }).then((currentToken) => {
if (currentToken) {
    token = currentToken;
    console.log(currentToken);
} else {
    // Show permission request UI
    console.log('No registration token available. Request permission to generate one.');
}
}).catch((err) => {
    console.log('An error occurred while retrieving token. ', err);
 });

 fcm.onMessage((data) => {
     // in here you call
     g1.refresh(getRandomInt(50, 100));
     g2.refresh(getRandomInt(50, 100));
     g3.refresh(getRandomInt(0, 50));
     g4.refresh(getRandomInt(0, 50));
 }

0
投票

para poder cambiar el valor lo tenes en

var g4 = 新 JustGage({ id: 'g4', /* en el plc 变量名称 / value: 70, / aca se coloca la variable del plc, en un s7 /// value: ':="nombre_de_la_variable":', /////*/

© www.soinside.com 2019 - 2024. All rights reserved.