PAC Control on EPIC

Can confirm this package works with my example, @Beno was right, I had tested it on a different version of Node-RED running on my Windows machine — my bad!

I updated the reply and example above to use this pdfmake node and tested it on my EPIC with Node-RED v3.1.7 and it works without issue.

@Beno node installed via manage pallet menu. Thank you.
@torchard Flow imported as a new flow. Thank you.
Tried to use the following data:
17:29:39,IN,30
17:29:49,IN,40
17:29:55,IN,50
17:30:18,OUT,80
17:30:26,IN,35
17:30:34,OUT,60
18:58:21,IN,30

No PDF created. Tried a payload of:

Where am I going wrong, please guys?

How is your data coming in? Directly from a PAC Control read node pulling in the table, or an inject node?

If it is an inject node, make sure it’s set to send msg.payload as a JSON object, I’ve seen that get reconfigured as a blank string during import some times.
image

Then, when you click the three dots on the right, make sure it’s got the square brackets at the top and bottom and quotes around each value — this is so that it matches the format that the PAC read node will be sending:
image

[
    "",
    "17:29:39,IN,30",
    "17:29:49,IN,40",
    "17:29:55,IN,50",
    "17:30:18,OUT,80",
    "17:30:26,IN,35",
    "17:30:34,OUT,60",
    "18:58:21,IN,30",
    "",
    "",
    "",
    "",
    ""
]

EDIT: You can confirm this is working correctly if the debug shows msg.table as an array[7]
image
If msg.table isn’t a two dimensional array, or basically an array of arrays, then it won’t match pdfmake format and won’t make the file correctly, which is why you won’t see any file created.

1 Like

Perfect!
I had forgotton to change payload from string to JSON.
Now works as you describe.
Thank you for spending time to do this, it is much appreciated. I will now try to modify to achieve the attached report, then have it emailed once a day!!!


Here’s the PFDMake file layout for those that are interested:

var dd = 
{
  "content": [
    {
      // Header and date in the same line
      "columns": [
        {
          "text": 'DYR Daily Tank Report',
          "style": 'header',
          "alignment": 'left'
        },
        {
          "text": '30/09/2024',
          "style": 'header',
          "alignment": 'right'
        }
      ],
      "margin": [0, 0, 0, 10] // Adding margin below the header line
    },
    
    // Tank 1 Table
    {
      "style": "tableExample",
      "alignment": "center",
      "table": {
        "widths": ['*', '*', '*'],
        "headerRows": 1,
        'body': [
          [{ "text": 'Tank 1', "style": 'tableHeader', 'colSpan': 3, "alignment": "center" }, {}, {}],
          [{ "text": 'Movement Time', "style": 'tableHeader', "alignment": "center" },
           { "text": 'In/Out', "style": 'tableHeader', "alignment": "center" },
           { "text": 'Volume', "style": 'tableHeader', "alignment": "center" }],
          ['10:49:08', 'IN', '100'],
          ['10:49:47', 'IN', '50'],
          ['10:50:11', 'IN', '50'],
          ['10:50:39', 'IN', '50'],
          [{ 'colSpan': 3, "text": ''}, {}, {}],
          [{ "text": 'Total Movements In:', "style": 'tableHeader', 'colSpan': 2, "alignment": 'right' }, '', '4'],
          [{ "text": 'Total Movements Out:', "style": 'tableHeader', 'colSpan': 2, "alignment": 'right' }, '', '0'],
          [{ "text": 'Total Volume In:', "style": 'tableHeader', 'colSpan': 2, "alignment": 'right' }, '', '250'],
          [{ "text": 'Total Volume Out:', "style": 'tableHeader', 'colSpan': 2, "alignment": 'right' }, '', '0']
        ]
      }
    },

    // Tank 2 Table
    {
      "style": "tableExample",
      "alignment": "center",
      "table": {
        "widths": ['*', '*', '*'],
        "headerRows": 1,
        'body': [
          [{ "text": 'Tank 2', "style": 'tableHeader', 'colSpan': 3, "alignment": "center" }, {}, {}],
          [{ "text": 'Movement Time', "style": 'tableHeader', "alignment": "center" },
           { "text": 'In/Out', "style": 'tableHeader', "alignment": "center" },
           { "text": 'Volume', "style": 'tableHeader', "alignment": "center" }],
          ['10:49:47', 'IN', '100'],
          ['10:50:11', 'IN', '50'],
          ['10:50:39', 'IN', '50'],
          [{ 'colSpan': 3, "text": ''}, {}, {}],
          [{ "text": 'Total Movements In:', "style": 'tableHeader', 'colSpan': 2, "alignment": 'right' }, '', '3'],
          [{ "text": 'Total Movements Out:', "style": 'tableHeader', 'colSpan': 2, "alignment": 'right' }, '', '0'],
          [{ "text": 'Total Volume In:', "style": 'tableHeader', 'colSpan': 2, "alignment": 'right' }, '', '200'],
          [{ "text": 'Total Volume Out:', "style": 'tableHeader', 'colSpan': 2, "alignment": 'right' }, '', '0']
        ]
      }
    },

    // Tank 3 Table
    {
      "style": "tableExample",
      "alignment": "center",
      "table": {
        "widths": ['*', '*', '*'],
        "headerRows": 1,
        'body': [
          [{ "text": 'Tank 3', "style": 'tableHeader', 'colSpan': 3, "alignment": "center" }, {}, {}],
          [{ "text": 'Movement Time', "style": 'tableHeader', "alignment": "center" },
           { "text": 'In/Out', "style": 'tableHeader', "alignment": "center" },
           { "text": 'Volume', "style": 'tableHeader', "alignment": "center" }],
          ['10:50:11', 'IN', '50'],
          ['10:50:39', 'IN', '100'],
          [{ 'colSpan': 3, "text": ''}, {}, {}],
          [{ "text": 'Total Movements In:', "style": 'tableHeader', 'colSpan': 2, "alignment": 'right' }, '', '2'],
          [{ "text": 'Total Movements Out:', "style": 'tableHeader', 'colSpan': 2, "alignment": 'right' }, '', '0'],
          [{ "text": 'Total Volume In:', "style": 'tableHeader', 'colSpan': 2, "alignment": 'right' }, '', '150'],
          [{ "text": 'Total Volume Out:', "style": 'tableHeader', 'colSpan': 2, "alignment": 'right' }, '', '0']
        ]
      }
    }
  ],

  "styles": {
    "header": { "fontSize": 18, "bold": true, "margin": [0, 0, 0, 10] },
    "tableExample": { "margin": [0, 0, 0, 50], "color": "blue" },
    "tableHeader": { "bold": true, "fontSize": 13, "color": "black" }
  },

  "defaultStyle": { "alignment": "center" }
}

2 Likes

When it comes time to send the PDF via email attachment once a day…
This thread should get you up and running much quicker.

2 Likes

@Beno @torchard @philip
Thank you all for your support and time on this it was much appreciated.

I can confirm that @torchard JSON PDFMake flow works perfectly. I will try and use this as a template to accommodate the JSON I posted above. Also, your flow for email worked as well but I had a bit of trouble with Gmail configuration!!!

For anyone creating a new Gmail account, once set up with your username and password, you need to enable two factor authentication. Once that’s done, create an App Password, which the flow will need.
This is the part that took some time as Google ended up saying I had incorrectly logged in too many times, but today it finally gave me the option to create the App Password for the EPIC.
Here’s what the email node should look like:
Email Node Configuration
Username is your new gmail address and password is the App Password created.

3 Likes

Thanks for the feedback.
Glad to hear you got it working.

Google changed things a while back: Google Apps ending access to less secure apps - are you ready?
Its also been mentioned in the forums a few times, but perhaps its worth a re-visit and update the screenshots as they have changed things around a bit.
As you say, the key is to make an application specific password just for Node-RED (and one for groov View etc).

1 Like