0

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.

WhatsYourFunction
  • 621
  • 1
  • 9
  • 25

1 Answers1

1

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.

romkey
  • 6,218
  • 3
  • 16
  • 12
  • Thanks for that. Re compiled -- should have known -- of course. Re security: the J5 runs on LAN-only server. If we do open it up to WAN it will be as an API with only a limited set of commands exposed. – WhatsYourFunction Jun 07 '19 at 04:14