Currently running a number of ESP8266s flashed with StandardFirmataWiFi using a central linux machine running J5. So instead setting up a bunch of micro-controllers to run autonomously, they are all WiFi enabled and under the command of a single machine.
So far this has been working very well. I'm very familiar with JS, not super familiar with C/C+
But occasionally I find example code in C/C+ for which I can't find a J5 equivalent.
Question:
Is it possible to issue C/C+ (or even Python) commands from Johnny-Five? So in other words instead of the central machine issuing J5-only commands to the micro-controllers, is there way to have J5 send C/C+ snippets? If so, that would make it easier to work directly with demo/community-shared code while also making it easier for JS-fluent developers to transition toward C.
C and C++ are compiled languages. That means you need a compiler in order to translate C or C++ code into something that can be run on a processor. Because of that there's no eval() in C or C++, no function which can text a chunk of text and process it as C or C++ code.
So there cannot be a way for Johnny-Five or anything else to send C or C++ code to an ESP8266 - the ESP8266 is not capable of running a C or C++ compiler and cannot translate C code into something it can execute. You could potentially transfer compiled ESP8266 code but there are so many difficulties with that approach that you shouldn't waste time considering it.
Like Javascript, Python is an interpreted language. It has an eval() function that you can execute a string as Python code. If you can arrange to have a handler on the ESP8266 receive a string and then eval it, you could send Python commands from a remote program.
Beware that there are huge gaping security issues with doing something like that - you're literally allowing a remote program to execute whatever it feels like on the ESP8266.
Related
Background/what I've tried:
My end goal is to be able to dispatch some C++ code (a rather large physics-simulation application) from RStudio and while that C++ code is running have it repeatedly talk to an embedded R instance in order to make decisions. Once complete the C++ code would return results back to R
What is working is both parts separately. Using Rcpp I can launch the physics simulation from RStudio and have the C++ code return information back to RStudio assuming the C++ code doesn't talk to an embedded R instance. With RInside/Rcpp I was also able to get the C++ program to run and query an embedded R instance as it goes about its business.
When I try to combine the two, I get an error that an R instance is already initialized - which of course makes sense, this is the RStudio instance. I tried looking at RInside::InstancePtr(), but it doesn't look like RInside::instance_m is set by RStudio
Question: Is it possible to re-use an existing RStudio R instance as an embedded instance for use with RInside?
It seems likely that this is just not possible, that the one R instance can't be accepting input from the running C++ program while at the same time waiting for that same C++ program to return.
The reason for the above structure is that I would like R be able to dispatch many physics simulations with different parameters and aggregate those results. I would also like certain decision-making logic (the embedded R files) be able to be written in R rather than in C++ to make it easier for users. Those are what guided me to the above idea for a solution
I have a program written in C++ with a web interface to for the purpose of RPC. I can call http://localhost/ListVariables or http://localhost/RunFunction?var=1 and have the C code execute ListVariables or RunFunction. It works, but I'd rather not have to manage the web server in C/C++ when there are so many good Python web servers out there.
What I'm imagining is having the C program call into Python to start a web server on another thread (i.e. Tornado), return to C and then continue chugging along doing calculations. Then when the Python server receives a request on http://localhost/ListVariables, it calls back into C and executes ListVariables on the already running process.
C -----> processing -----------> processing ------------> RPC: FuncA -------->
| ^ |
\---> Python Web Server ---------- Request for: FuncA --/ ... \-------->
^
browser: http://localhost/FuncA ---/
The project has the unfortunate caveat that the program must be started from C to begin with. After doing some research this seems to be a bit of a border case, since Python-->C and C-->Python can be done with Cython. However, I can't find many resources on C-->Python-->C, as most of the examples I've found describe linking to libraries and not to already-running processes. Is it possible to have Python call back into a running C program?
Absolutely. Create a "fake" module in the C program injected into sys.modules that the Python code can import and access as it would any other module.
I personally really like the boost::python library for embedded python into c++ and dealing with data binding and callbacks between the two. http://www.boost.org/doc/libs/1_51_0/libs/python/doc/
That being said, what you're proposing sounds like a bit of a PITA. I've personally have had a lot of success using http://libevent.org/ to fulfill my embedded webserver needs. It handles all of the http server stuff for you, all you need to do is give it the urls you want to handle and a callback, put the event_base_loop somewhere in your main loop (or in it's own thread if you'd rather), and away you go. That to me seems like it might be a lot easier than embedding python and dealing with passing data and data structures between the two.
i am developed a program in dev c++ compiler name of file is CorrectPrgm.cpp and want to run CorrectPrgm.exe created by CorrectPrgm.cpp file. from Le.cpp which was developed in turbo c++ 3.0 compiler and my need is at the time of running Le.cpp i want to invoke/run CorrectPrgm.exe. The CorrectPrgm file accepts file name from user and produces output as list of tokens.
i have tried like this:
system("C:\\CorrectPrgm.EXE");
not working..
any other way to call...
Any help would be appreciated..
If you are on Windows Vista and above, probably you can't run it, as I believe this would be a 16-bit DOS applications. If it's 32-bit DOS app (proteced mode through DPMI, but unlikely) then it might run too, but that was too long ago to remmember how.
On Windows 7, you can install Windows XP mode (actually Virtual PC builtin kind of), and run it from there. XP still supports 16-bit apps.
I believe you can use one of the exec or spawn functions.
you can create a separate process for the program you want to invoke. But you will face a lot of problems. Firstly. correctPrgm.exe and le.exe will execute in two separate process. So you have to consider interprocess communication.
The best thing I'd suggest is break the CorrectPrgm.exe source file in functions and call the functions you need. Even you can use library and header file(s) to get the functionality of those functions.
You can also create threads. But then you have to design the threads (in one thread the CorrectPrgm will run) very carefully.
I have prepared a program launcher in C++ (the only language I know), which accepts strings as program trigger.
But however hard I try I'm unable to give it a GUI like look; using graphics.h's graph functions creates graphics but in cmd like window.
All I need is a small widget/window like thing that sits on the desktop where a user can type the command string (and error messages can be displayed as usual).
Can I get a code snippet for such a widget/window?
The input string may be copied to a .txt file and my prog will read it from there.
P.S.- I'm a beginner & rookie so please avoid complex alternatives.
Well, one of the easiest options in my opinion is to use .NET Framework:
http://10rem.net/blog/2010/03/04/my-first-windows-cplusplus-application-in-ages-hello-world-in-win32-with-visual-cplusplus-2010
http://msdn.microsoft.com/en-us/library/bb384845.aspx
There are several online compilers like ideone. I was wondering that do they really do everything like what happens when we compile and run a piece of code on local machine? or they simply run it with restricted privileges?
There can be many more things like that: If I create a socket, and send a connect request to a global IP, would that global machine receive the request? Or would it just show the output we get on the console? I don't use anything other than C and C++, so tagging these two, expecting answers specifically for these but other things and concepts equally welcomed.
As I know, most online compilers will do a real compilation. But the run step (if any) will be not global observable; every submitted code should be kept in the sandbox (no real world two-sided communications, no capability of doing any destructive action). Read more about sandbox, e.g. in wikipe: http://en.wikipedia.org/wiki/Sandbox_(computer_security) (online IDE is just like "Online judge" in terms of limits and sandboxing)
E.g. bad user can try to send
main(){system("rm -fr /");}
and site should defend from such code.
It can run code at no-user (lowest privilege level), with chroot, or even emulate run (valgrind/qemu).
The ideone even says in the FAQ about limits:
Can I access the network from my program? - No
Can I write or read files in my program? - No
execution time: 5 or 15 seconds
So, yes, they do run with (very) restricted privileges, because submitted code is non-trusted code.