Last modified by Hera Guo on 2024/11/11 16:48

From version 4.1
edited by Hera Guo
on 2024/11/07 15:49
Change comment: There is no comment for this version
To version 5.1
edited by Hera Guo
on 2024/11/07 16:03
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -372,12 +372,107 @@
372 372  
373 373  [[image:1730965718765-507.png]]
374 374  
375 +When selecting the All Messages mode, the data format received by downstream nodes is as follows:
375 375  
377 +{{code language="none"}}
378 +[{
379 + "msg": {
380 + "temperature": 26,
381 + "humidity": 31
382 + },
383 + "metadata": {
384 + "deviceType": "default",
385 + "deviceName": "device-01",
386 + "ts": "1703490713006"
387 + }
388 +}, {
389 + "msg": {
390 + "temperature": 12,
391 + "humidity": 16
392 + },
393 + "metadata": {
394 + "deviceType": "default",
395 + "deviceName": "device-01",
396 + "ts": "1703490718019"
397 + }
398 +}, {
399 + "msg": {
400 + "temperature": 15,
401 + "humidity": 16
402 + },
403 + "metadata": {
404 + "deviceType": "default",
405 + "deviceName": "device-01",
406 + "ts": "1703490723041"
407 + }
408 +}, {
409 + "msg": {
410 + "temperature": 13,
411 + "humidity": 10
412 + },
413 + "metadata": {
414 + "deviceType": "default",
415 + "deviceName": "device-01",
416 + "ts": "1703490728061"
417 + }
418 +}, {
419 + "msg": {
420 + "temperature": 12,
421 + "humidity": 18
422 + },
423 + "metadata": {
424 + "deviceType": "default",
425 + "deviceName": "device-01",
426 + "ts": "1703490733073"
427 + }
428 +}]
376 376  
430 +{{/code}}
431 +
377 377  === 6.3.5 script ===
378 378  
379 379  
435 +This node allows developers to customize data transformations through code, and can modify the content and format of data sent downstream through code logic. The node configuration content is as follows:
380 380  
437 +**Name:** required field, indicating the name of the node;
438 +
439 +**Function Transform: **Code (customizing transformation rules through code), the input parameters of the function include msg (message), metadata (metadata), msgType (message type pushed by the previous node), and the return value should be in a fixed format {msg: newMSG, metadata: newMetadata, msgType: newMgType}, where the value is the object we have changed;
440 +
441 +**Explanation:** Non mandatory field, additional explanation;
442 +
443 +According to the running results, there are two types of exits for this rule node: Success and Failure.
444 +
445 +A simple usage example is as follows:
446 +
447 +Transform logical code:
448 +{{code language="none"}}msg.timestamp = metadata.ts;
449 +msg.province = 'GUANGDONG';
450 +msg.city = 'SHENGZHENG';
451 +return {
452 + msg: msg,
453 + metadata: metadata,
454 + msgType: msgType
455 +};{{/code}}
456 +
457 +Data received by downstream nodes:
458 +
459 +{{code language="none"}}
460 +{
461 + "temperature": 21,
462 + "humidity": 15,
463 + "timestamp": "1703491991280",
464 + "province": "GUANGDONG",
465 + "city": "SHENGZHENG"
466 +}
467 +
468 +{{/code}}
469 +
470 +(% class="wikigeneratedid" %)
471 +Example usage:
472 +
473 +(% class="wikigeneratedid" %)
474 +[[image:1730966616929-747.png]]
475 +
381 381  == 6.4 action ==
382 382  
383 383  === 6.4.1 math function ===
1730966616929-747.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.hera
Size
... ... @@ -1,0 +1,1 @@
1 +189.3 KB
Content