Real-time web communication (embedded ljnux) - c++

I want to make a smart little project where I receive data from an embedded linux (petalinux) into a phonegap app (Android).
The question is, what type of protocols are prefered?
I recently read about socket io and it looks great.
But how can I get the app to communicate from for example c or c++ to javascript and html?
The data will probably be stored into a sqlite database inside the embedded linux, or will someone prefer a better real time database system (RTDBS)?
Any ideas? Thanks.

Related

How to connect to SQL database on a Windows CE Application for ARM

I'm trying to send queries to a SQL database from a Windows CE 7 C++ application running on an ARM architecture.
During my research I found several possibilities to do this:
Use methods from system.data.sqlclient
Doesn't work, since the application is not supporting CLR
Use ODBC or OLEDB
I read at several points that both won't work on Windows CE
Use HTTP requests from winInet to send the data as JSON to the DB and parse it back there
Just an assumption that this could work, not confirmed
So I'm wondering what other/better ways there are to send these queries.
Thanks for your help!
If it is a pocket pc sql server lite database then you can use ADOCE to access and configure your database. The service'esqe approach is also valid and will take the data access burden from your client application.
you can implement your third option but you need to implement also another software component (on the SQL server side) to do the following work:
connect to the database;
decode the JSON and query the database;
encode the database answer in JSON and send back to your WEC7 application.
If you are familiar with C# and if you have .NET compact framework installed on your WEC7 machine you could also implement the software component that will send HTTP REQUEST in plain C# (without the need to study wininet).
Hope this helps

C++ Builder - File transfer

I am using Embarcadero C++ Builder and I am trying to collect as much information as I can so that I can start making my program. I want to make a client/server program. I am going to use databases and I need a way to transfer the database from the client computer to my server computer. And if a client PC gets destroyed for real I need to send the client his database back.
How can I do this?
I'm assuming you'll be using Firebird for your database, since it's the default for C++Builder/Delphi. Firebird maintains its database in a single file, so you will need to transfer it with network components, like Indy, a great socket library that comes with C++Builder. Here is an article about data transfer through network with Delphi (easily translatable to C++). Good luck!

web interface for C++ app on embedded Linux device

I'd like to implement a communication link between an Apache-hosted webpage and my custom C++ app running on a small Linux device such as a Raspberry Pi or a DD-Wrt.
There's a tutorial here for the Raspberry Pi that uses buttons on a webpage to control LEDs on GPIO pins. The example uses MySQL as a communication interface between the webpage and a script and the script has read/write access to GPIO. Although MySQL offers the advantage of mature/ubiquitous interfaces to Apache hosted webpages and to C++, it might slower and have a larger flash & RAM footprint than necessary.
In an attempt to find a communications link that is smaller/faster than MySQL, I have an example that uses Javascript that does XML-RPC to a C++ app. But, this post way back in 02-24-2012, implies that xmlrpc is obsolete and could be replaced by something more modern (JSON, REST) but the posts lacks details about these methodologies.
Another option considered is something like Wt or other embedded libraries, but it will have a learning curve and web developers aren't likely to be familiar with it.
My question is: what would be a good architecture to implement a web interface for a custom C++ app on a resource-constrained device like a Raspberry Pi or other embedded Linux device?
Assumptions:
Apache is prefered because it fits in memory and web developers are familiar with it.
Interface should be 'modern'
pages are simple text-only, about 10 pages, 90% of the data fields
are read-only and the other 10% are editable fields.
The webserver is on a private network with no more than 3 users. The qty of users is
enforced using security/login.
Embedded ARM platform that boots from SD
CGI (launching a process for each transaction) is assumed to be slower
than necessary. FastCGI might be OK.
Similar questions found that didn't answer my question:
- Language Choice for Web interface on embedded device
- Designing Web Interface for Embedded System
Oh god. Apache? Why would you want such an overkill monster on an embedded device? I would suggest using a smaller server and instead of using cgi use a rest api handler. A very lightweight setup is to use uhttpd with ubus plugin and then to write your system code in C and just expose it's functionality through json api on ubus. You can then completely separate your web interface from your system code and you can minimize strain on the embedded server by only serving static html which you turn into a dynamic application with javascript and ajax.
No interpreter, no cgi, just ajax and ubus backend.
I do that and more on my rPI using Nodejs with the express, Socket.io, Mongojs modules

How to communicate between C++ server app and django web app

I have some framework doing specific task in C++ and a django-based web app. The idea is to launch this framework, receive some data from it, send some data or request and check it's status in some period.
I'm looking for the best way of communication. Both apps run on the same server. I was wondering if a json server in C++ is a good idea. Django would send a request to this server, and server would parse it, and delegate a worker thread to complete the task. Almost all data that need to be send is string-like. Other data will be stored in database so there is no problem with that.
Is JSON a good idea? Maybe you know some better mechanism for local communication between C++ and django?
If your requirement is guaranteed to always have the C++ application on the same machine as the Django web application, include the C++ code by converting it into a shared library and wrapping python around it. Just like this Calling C/C++ from python?
JSON and other serializations make sense if you are going to do remote calls and the code needs to communicate across machines.
JSON seems like a fair enough choice for data serialization - it's good at handling strings and there's existing libraries for encoding/decoding JSON in both python & C++.
However, I think your bigger problem is likely to be the transport protocol that you use for transferring JSON between your client and server. Here's some options:
You could build an HTTP server into your C++ application (which I think might be what you mean by "JSON server" in your question), which would work fine, though might be a bit of a pain to implement unless you get a hold of a library to handle the hard work for you.
Another option might be to use the 0MQ library to send JSON (or otherwise) messages between your client and server. I think this would probably be a lot easier than implementing a full HTTP server, and 0MQ has some interprocess communication code that would likely be a lot faster than sending things over the network.
A third option would just be to run your C++ as a standalone application and pass the data in to it via stdin or command line parameters. This is probably the simplest way to do things, though may not be the most flexble. If you were to go this way, you might be better off just building a Python/C++ binding as suggested by ablm.
Alternatively you could attempt to build some sort of job queue based on redis or something other database system. The idea being that your django application puts some JSON describing the job into the job queue, and then the C++ application could periodically poll the queue, and use a seperate redis entry to pass the results back to the client. This could have the advantage that you could reasonably easily have several "workers" reading from the job queue with minimal effort.
There's almost definitely some other ways to go about it, but those are the ones that immediately spring to mind.

Integrating C++ code with any web technology on Linux

i am writing an program in c++ and i need an web interface to control the program and which will be efficient and best programming language ...
Your application will just have to listen to messages from the network that your web application would send to it.
Any web application (whatever the language) implementation could use sockets so don't worry about the details, just make sure your application manage messages that you made a protocol for.
Now, if you want to keep it all C++, you could use CPPCMS for your web application.
If it were Windows, I could advice you to register some COM component for your program. At least from ASP.NET it is easily accessible.
You could try some in-memory exchange techniques like reading/writing over a localhost socket connection. It however requires you to design some exchange protocol first.
Or data exchange via a database. You program writes/reads data from the database, the web front-end reads/writes data to the database.
You could use a framework like Thrift to communicate between a PHP/Python/Ruby/whatever webapp and a C++ daemon, or you could even go the extra mile (probably harder than just using something like Thrift) and write language bindings for the scripting language of your choice.
Either of the two options gives you the ability to write web-facing code in a language more suitable for the task while keeping the "heavy lifting" in C++.
Did you take a look at Wt? It's a widget-centric C++ framework for web applications, has a solid MVC system, an ORM, ...
The Win32 API method.
MSDN - Getting Started with Winsock:
http://msdn.microsoft.com/en-us/library/ms738545%28v=VS.85%29.aspx
(Since you didn't specify an OS, we're assuming Windows)
This is not as simple as it seems!
There is a mis-match between your C++ program (which presumibly is long running otherwise why would it need controlling) and a typical web program which starts up when it receives the http request and dies once the reply is sent.
You could possibly use one of the Java based web servers where it is possible to have a long running task.
Alternatively you could use a database or other storage as the communication medium:-
You program periodically writes it current status to a well know table, when a user invokes the control application it reads the current status and gives an appropriate set of options to the user which can then be stored in the DB, and actioned by your program the next time it polls for a request.
This works better if you have a queuing mechanism avaiable, as it can then be event driven rather than polled.
Go PHP :) Look at this Program execution Functions