Calling Shell command

Homegenie uses python2 … But by running the script from Shell I use python3 and all work fine. (rpi-rf call a python3).
Recalling the file from Shell, it should not affect the Pyhthon version of HG, is that correct? (In fact from Shell the Bash file is executed correctly).

and… The system default Python version is 2.7… but the script calls python3 for the execution of the preogram.

Please, also consider that the script works without any problems even from the raspbian crontab…For this reason I was wondering if perhaps you are able to call the script from homegenie via other ways…

What exactly is the purpose of your Python program. What does it do and why did you create it in Python 3.

Mixing Python versions is not something I’ve ever needed to do but this might give you an insight into how it can be done. https://stackoverflow.com/questions/27863832/calling-python-2-script-from-python-3

I’m assuming you created your bin bash script correctly, made it executable properly and had the absolute path correctly defined.

As you say it runs fine from the cli so I imagine your problem is either path related or there’s a problem between Python versions.

Ok I remember seeing a problem similar to yours in the old forum. Read through this as it may contain a solution for you. It explains why you can run as a user from the command line but not as sudo http://old.homegenie.club:8080/www.homegenie.it/forum/index377e.html?topic=352.0

1 Like

Thank you very much Tuiceman and Pretediscrete, because with your help I finally managed to send the Shell command via HG.

I don’t know why, but after so many tests this is the complete script that works:

var proc = new System.Diagnostics.Process {
StartInfo = new System.Diagnostics.ProcessStartInfo {
FileName = “/bin/bash”,
Arguments = "-c “sudo -H -u pi " + “”/usr/local/sendrf.sh”,
UseShellExecute = false,
RedirectStandardOutput = true,
}
};
proc.Start();
Program.Notify("xxx: ", “xxx”);

Yes because as I originally mentioned you were trying to run the script without the use of sudo. You can see the difference in the last link I sent you from the old HomeGenie forum. Compare the two and you’ll see the difference.

This line made all the difference

FileName = “sudo -H -u pi bash”,

Compare that to your original script and you’ll know why it ran successfully

I suggest that you tidy up the post so others searching for a solution to the same problem will find it easily. Probably best to make a new post with your findings.

I pretediscrete,
I came to the solution thanks to your suggestion, but I don’t know why by moving “sudo -H -u pi” in the Filename instead of in the Arguments, the script doesn’t work. Mixing the Tuiceman scripts and your suggestions I came to the above script, and it work fine…
Thank you very much.
P.S.How do you think it would be better to fix the post??

Just make a “How to” post outlining what you were trying to achieve and your final solution.

As I mentioned a lot of what you were trying to achieve had already been documented in the old forum. Unfortunately it is quite difficult to search now as it is an archived forum.

You need to be patient and follow the posts from start to finish. It can save you a lot of time. Many current users have obtained solutions to their problems there.

Did you try to construct a C# solution to your problem. The reason I ask is that HG has native support as you already know.

Be mindful that HG is using Python v 2. If you are using Python 3 on the same machine I’d install it in a virtual environment to avoid any possible issues with two different versions.

Glad to hear you finally resolved your issue.

@roberto1979 glad to see you got it figured out

@roberto1979 could you post your sendrf.sh script here. I’d be interested to see what it would look like scripted in C#.

Hi Pretediscrete,
You’re right, it would be much more linear to write it directly in C#.
Above is the script… “110022” is the parameter (RF Code to send)…
(Send.py is the Python program from rf-rpi - https://github.com/milaq/rpi-rf )

#! /bin/bash
cd /
/usr/bin/python3 /usr/local/bin/homegenie/send.py 110022

I see it’s derived from an Arduino sketch so calling a C++ routine from within C# shouldn’t pose a problem.

Are you using an RF transmitter on the GPIO pins to send your RF commands.

1 Like

Peter, exactly like that.
I use an RF transmitter XL-R03A connected to the GPIO…
(Some time ago, i tried also with Broadlink RM, but the new versions PLUS_300, seem to work with IR, but not with RF)…

Where are you based. I’m based in Europe and I set up an RM Pro + for someone recently. RF is working fine but if you can go the RPI route using the GPIO pins you’ll have a lot more control over your project.

I also live in Europe … I tried a Broadlink Serial Number S / N: RM34H…
I read on other forums that many peaople have had problems since the 33 series … with RF Broadlink…

(Even with Broadlink Manager for windows, there are no problems with IR, but it does not work with RF.
Please, do you remember the serial number of the Broadlink you installed?)

Yes RM3322247096.

You do know these units were dogged with problems for quite a while. Have you managed to track down a working firmware for your unit.