Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The possibility of including the "post" method in the webapi plugin #650

Closed
JefersonBigheti opened this issue Dec 26, 2022 · 9 comments
Closed

Comments

@JefersonBigheti
Copy link

First of all congratulations for the excellent project. I would like to know if there is a possibility to include the "post" method in the webapi plugin.

@unocelli
Copy link
Member

unocelli commented Dec 26, 2022

Hi, thank you for your appreciation.
we have the feature planned but our resources are currently limited.

there is a functionality to configure via a environment variable DEVICES the webapi get to read tag properties and post to write values

@tayfunonbasioglu
Copy link

The post method or a webhook-like method can make a lot of work easier. I will eagerly await this.

@tayfunonbasioglu
Copy link

image

@JefersonBigheti
Copy link
Author

I'm having trouble implementing it. Would you have an example of how to implement post using your suggestion "environment variable DEVICES"

@unocelli
Copy link
Member

  • your web application (device) have to serve the REST API get and post (exp. GET -> http://localhost:8080/api/tags POST -> http://localhost:8080/api/tags)
  • you modify the environment parameter envParams.js configs.getTags and configs.postTags with your GET/POST url.
  • you start fuxa server with arguments node main.js --env=test
  • in UI you can ask in the connection section the tags configured in your web application through GET (normally will be asked by start)
    image

The tags must be in an array (flat structure) as you can see in the following example

var tags = [
    {
        id: 'tempA',     // UUID
        name: 'tempA',
        value: 0,
        type: 'number'  // number|boolean|string,`
    },
    {
        id: 'tempB',    // UUID
        name: 'tempB',
        value: 0,
        type: 'number'  // number|boolean|string,`
    }
]
apiApp.get('/api/tags', function (req, res) {       
    res.json(tags);
});

apiApp.post('/api/tags', function (req, res) {
    if (req.body && Array.isArray(req.body)) {
        for(let i = 0; i < req.body.length; i++) {
            for (let y = 0; y < tags.length; y++) {
                if (req.body[i].id === tags[y].id) {
                    tags[y].value = parseFloat(req.body[i].value);
                    y = tags.length;
                }
            }
        }
    }
    res.end();
});

@JefersonBigheti
Copy link
Author

The example shown worked very well.
Thanks a lot for the help!

@RajatDas2020
Copy link

RajatDas2020 commented Aug 2, 2024

Hi actually I have a opcua client running in fuxa. From a standalone opcua server I am able to get the opcua variables in fuxa. Now these opcua variables I want to expose to the application layer (upper layer) so that the application can read write the opcua variables. can you kindly guide me how to do that ?

@unocelli
Copy link
Member

unocelli commented Aug 17, 2024

@RajatDas2020 Hi, I will use mqtt, install a broker (mosquitto) and export the opcua values

@henjoe
Copy link

henjoe commented Sep 27, 2024

Hi @unocelli I am trying to use this application but seems like the WebAPI properties only works on GET ?
image

Am I missing something here? or the Post method already removed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants