c++ app web interface
HI all,
This is more of a general programming question and not to do so much with rev pi but here go's anyway. I have my revpi running a c++ app in the background just doing some basic control with sensors and switching outputs. I now would like to make a web page that can be viewed locally (using Apache 2) to show the values of the sensors values and be able change user settings that are in the c++ app. but i find myself very lost when i look a how to make the c++ app communicate with the web page. I don't really want to use PROCON as in the end would like to some web framework(bootstrap) to keep things looking fresh (sorry rev pi guys ).
When i think about how this should work. I think that the web page would call a JS function to ether create a pipe or read some memory location. but im not sure is this a the best way to do this is. Or even the correct way to do so.
would be great to know your thoughts. Thanks for you time !
This is more of a general programming question and not to do so much with rev pi but here go's anyway. I have my revpi running a c++ app in the background just doing some basic control with sensors and switching outputs. I now would like to make a web page that can be viewed locally (using Apache 2) to show the values of the sensors values and be able change user settings that are in the c++ app. but i find myself very lost when i look a how to make the c++ app communicate with the web page. I don't really want to use PROCON as in the end would like to some web framework(bootstrap) to keep things looking fresh (sorry rev pi guys ).
When i think about how this should work. I think that the web page would call a JS function to ether create a pipe or read some memory location. but im not sure is this a the best way to do this is. Or even the correct way to do so.
would be great to know your thoughts. Thanks for you time !
Hello,
You can easily do it all via Modbus. The PI supports virtual devices (master / slave).
The whole thing you do then on a PC which acts as a web server. then should also run Modbus and have a socket connection. Now you can create a website which is then addressed via Javascript. You can then read the data via javascript from the modbus (PC) from the PI.
I do not do it differently Z.z.
You can easily do it all via Modbus. The PI supports virtual devices (master / slave).
The whole thing you do then on a PC which acts as a web server. then should also run Modbus and have a socket connection. Now you can create a website which is then addressed via Javascript. You can then read the data via javascript from the modbus (PC) from the PI.
I do not do it differently Z.z.
You say you would rather not like to have a Java framework at the end doing the cyclical update of a webpage. But actually what you have just suggested is the creation of such a framework
So why not using one of the frameworks which exist? Procon may be oversized for a small app but what are we talking about? Just some kind of dashboard? Then the future orientated way would definitely be using a cloud solution.
You could e.g. choose Node-Red and the build in connector to IBM cloud. The new TeamViewer for RevPi will also offer a cloud dashboard. All these solution swould need to get the process image data into the cloud agent running on RevPi and shifting the data into the cloud. But most of the time this is easy to realize (NodRed: Use a command node, TeamViewer: Use the MQTT broker's API or NodRed MQTT node etc., KUNBUS cloud: Use Linux socket and write to it,...etc.). With all these solutions you get the data to a cloud server and from there you can easily build your dashboard (drag &drop) which can be used any where, not just LAN based). When you build your own web server on your device instead of using a cloud agent you would always need to solve the security issues which have already been solved by cloud solutions. And the argument that by using a cloud solution you would involve a third party which you need to rely on is only valid if you campare it to a pure LAN solution. If you want to get your own web server's web pages into WAN you always rely on third party security and infra structure (like VPN provider etc). With TeamViewer you would have e.g. a very reliable 3rd party who is operating their servers in Germany (Frankfurt) and underlying completely German's and European's laws.
So why not using one of the frameworks which exist? Procon may be oversized for a small app but what are we talking about? Just some kind of dashboard? Then the future orientated way would definitely be using a cloud solution.
You could e.g. choose Node-Red and the build in connector to IBM cloud. The new TeamViewer for RevPi will also offer a cloud dashboard. All these solution swould need to get the process image data into the cloud agent running on RevPi and shifting the data into the cloud. But most of the time this is easy to realize (NodRed: Use a command node, TeamViewer: Use the MQTT broker's API or NodRed MQTT node etc., KUNBUS cloud: Use Linux socket and write to it,...etc.). With all these solutions you get the data to a cloud server and from there you can easily build your dashboard (drag &drop) which can be used any where, not just LAN based). When you build your own web server on your device instead of using a cloud agent you would always need to solve the security issues which have already been solved by cloud solutions. And the argument that by using a cloud solution you would involve a third party which you need to rely on is only valid if you campare it to a pure LAN solution. If you want to get your own web server's web pages into WAN you always rely on third party security and infra structure (like VPN provider etc). With TeamViewer you would have e.g. a very reliable 3rd party who is operating their servers in Germany (Frankfurt) and underlying completely German's and European's laws.
Unser RevPi Motto: Don't just claim it - make it!
Tanks for the responses.
ingo i think there has been some misunderstanding i would like to use the rev pi as my web server or from how i read your comment i think you mean how i can communicate between two diffrent pc or do i miss understand ?
volker I would like to use JS as my fount end using bootstrap as the framework. this will be a small app for sure i only have to control a few pumps, valves and heating elements. Taking reading form level sensors and temp sensors.
I understand using node red would be a easier way to achieve my goal. but I would like to get my hand a dirty while building up my knowledge of programming so i am trying to stay away form solution like node red.
using a cloud interface would be the next step after all is built and working. But i would still require a local interface to work in the even of loss of internet. I am not really looking to roll my own web server but instead use Apache 2 and just HTML, JS, CSS, etc to create a web page that pull/pushes values to/from the c++ app running in the back ground.
Team viewer seam a great way to help with the security and remote access and will definitely be being used.
currently when i log into my rev pi i can see revpi/pictory's web interface this is more or less the same a what i would like to do but just with the values being passed from my app
After doing some digging. iv found that i can achieve this in a number of way i.e
1. write a file in c++ in json then read the file in js and display the values.
2. use a socket to communicate the date form c++ to js
3. use a pipe to do the same.
of the methods above which would you say would be the best to use or is there any other options you would recommend ?
thanks
ingo i think there has been some misunderstanding i would like to use the rev pi as my web server or from how i read your comment i think you mean how i can communicate between two diffrent pc or do i miss understand ?
volker I would like to use JS as my fount end using bootstrap as the framework. this will be a small app for sure i only have to control a few pumps, valves and heating elements. Taking reading form level sensors and temp sensors.
I understand using node red would be a easier way to achieve my goal. but I would like to get my hand a dirty while building up my knowledge of programming so i am trying to stay away form solution like node red.
using a cloud interface would be the next step after all is built and working. But i would still require a local interface to work in the even of loss of internet. I am not really looking to roll my own web server but instead use Apache 2 and just HTML, JS, CSS, etc to create a web page that pull/pushes values to/from the c++ app running in the back ground.
Team viewer seam a great way to help with the security and remote access and will definitely be being used.
currently when i log into my rev pi i can see revpi/pictory's web interface this is more or less the same a what i would like to do but just with the values being passed from my app
After doing some digging. iv found that i can achieve this in a number of way i.e
1. write a file in c++ in json then read the file in js and display the values.
2. use a socket to communicate the date form c++ to js
3. use a pipe to do the same.
of the methods above which would you say would be the best to use or is there any other options you would recommend ?
thanks
Writing files on an eMMC is not the best idea. Each write/erase would bring the eMMC step by step closer to its life cycle's end. So using a socket or pipe should be the better choice. pleas ebe careful when using a web server over WAN. (or inside a LAN which is physically not secured against unauthorized access: E.g. our Web front end has not been designed to be public and login etc. is by far not secure enough to use it in internet environment. So if you design a front end to be used over the internet you will need to get deep into the security topic (e.g. allowing a user "pi" to sudo would not be a good idea for a public accessible system, etc.).
Unser RevPi Motto: Don't just claim it - make it!
yes i complete agree with the security risks i will be careful. that is a good point to keep in mind. I read that you guys are passing variables through the process image ? im going to take a read of the process image artical now if i can find it but if there is anything you could add it would be interesting to know.
thank you for your help !
thank you for your help !
HI,
yes you can think of the process image being a 4 kB memory area which can be accessed by piControl kernel driver using simple open seek, read and write calls (which are part of every program language like C, Python, Java). partly this process image is populated with data from IO modules by cyclical data exchange over the piBridge (done by piControl) partly (in case of your virtual modules) you could write and read whatever you like (call it exchange of variables). RevPi compatible third party software like Procon Web or Logi.cad is using this interface to access IO and so should any user software in order to remain compatibility for future modules and software.
yes you can think of the process image being a 4 kB memory area which can be accessed by piControl kernel driver using simple open seek, read and write calls (which are part of every program language like C, Python, Java). partly this process image is populated with data from IO modules by cyclical data exchange over the piBridge (done by piControl) partly (in case of your virtual modules) you could write and read whatever you like (call it exchange of variables). RevPi compatible third party software like Procon Web or Logi.cad is using this interface to access IO and so should any user software in order to remain compatibility for future modules and software.
Unser RevPi Motto: Don't just claim it - make it!
I have not had a chance to read up on it yet. But what you say is interesting and leads me to ask why would i use a pipe in my application over passing the variables to the process image with c++ and js ? what are the benefits/ disadvantages ? Dose the process image account for power cycles and retain the values ? Can you increase the size of the 4Kb ?
sorry i have so many questions !
sorry i have so many questions !
Hi,
no - values are not retained over power cycles. This is somewhat different to real PLCs which most of the time do have expensive buffered RAM for variables which are defined as "retain". If you need retained variables you need to write them into eMMC using standard file operations. Regular PLCs are also normally not retaining IO values, as such values are cyclically renewed and therefore a retaining does not make any sense.
If you are working with process values which are internal to your application and which are not shared with other hardware or software you should not use the process image but regular RAM (as every program language would do with a variable).
If you want to directly use a process value inside a dynamic web page there could be a good chance to do this by reading from the process image using open/seek/read calls. But this could be an issue for web server privileges and rights and I cannot say anything about that. Theoretically it should work but practically you might have to try...
no - values are not retained over power cycles. This is somewhat different to real PLCs which most of the time do have expensive buffered RAM for variables which are defined as "retain". If you need retained variables you need to write them into eMMC using standard file operations. Regular PLCs are also normally not retaining IO values, as such values are cyclically renewed and therefore a retaining does not make any sense.
If you are working with process values which are internal to your application and which are not shared with other hardware or software you should not use the process image but regular RAM (as every program language would do with a variable).
If you want to directly use a process value inside a dynamic web page there could be a good chance to do this by reading from the process image using open/seek/read calls. But this could be an issue for web server privileges and rights and I cannot say anything about that. Theoretically it should work but practically you might have to try...
Unser RevPi Motto: Don't just claim it - make it!
Ok that good to know thank you both for your help. I have been playing with pipes today and i think that using a normal file would be the way to go as writing to a pipes will hold the presses up if a read is available. May be a fork would sort this out but in haven't got that far yet. I can then save said file to a USB for storing variables that can be used after power cycles and as a back up.
Would you have any recommendations of how to format the file a file with variables int it ? I am thinking (which is dangerous !) to pass them into the file like "pump_request=true/n"
Would you have any recommendations of how to format the file a file with variables int it ? I am thinking (which is dangerous !) to pass them into the file like "pump_request=true/n"