fast-gpio pulses syntax from onion cloud (ubus syntax)



  • Hi,

    I have been trying to use the fast-gpio utility with the pulses option from onion cloud without success. I can make it work with the read option, which only takes a single parameter after the read, but the pulses needs 3 parameters. Does anybody now the syntax for it?

    Thank you,

    Ricardo.



  • The utility you're refering to is open-source at https://github.com/OnionIoT/fast-gpio/blob/master/src/main.cpp. You can see that the pulses option's help text is pulses <gpio> <path_pulses_file> <repeats> When given this option, the program will call the function pulseGpio(FastGpio *gpioObj,int pinNum, char* pathToFile, int repeats) here, which reads from the given file line-wise in the format %d,%d the times the pin is supposed to go up and down. This info is then given to void pulse(FastGpio *gpioObj,int pinNum,int highMicros, int lowMicros) in this function.

    In summary: Create a text file pulses.txt with the content

    100,20
    10,2000
    50,10
    

    Run it with pulses 9 pulses.txt 3

    It will then take GPIO 9, goes through each line and sets GPIO9 high for 100 microseconds, then low for 20 microseconds, then high for 10 microseconds, then low for 2000 microseconds, then high for 50 microseconds, then low for 10 microseconds, then repeat the whole thing 2 more times (repeat=3).



  • Thank you very much for your explanation. However, I have been successfully running the utility in its normal use case, which is from the command line in a shell. This works just fine:

    root@Omega:~# fast-gpio pulses 19 /root/input.csv 3
    Pulses GPIO19: r)wr)w,

    Now, I would like to run it from the Onion Cloud. Since one of methods to do it, is to use the ubus format, for debugging purposes, I ran ubus locally in the CLI, and I could get the read option to work:

    root@Omega:/# ubus call onion fast-gpio '{"params":{"read":"19"}}'
    {
    "cmd": "Read",
    "pin": 19,
    "val": "0"
    }

    However, I can't get the syntax of the pulses option right. I tried the following:

    root@Omega:/# ubus call onion fast-gpio '{"params":{"pulses":{"19","/root/input.csv","3"}}}'
    Failed to parse message data

    root@Omega:/# ubus call onion fast-gpio '{"params":{"pulses":{"19" "/root/input.csv" "3"}}}'
    Failed to parse message data

    root@Omega:/# ubus call onion fast-gpio '{"params":{"pulses":"19","/root/input.csv","3"}}'
    Failed to parse message data

    root@Omega:/# ubus call onion fast-gpio '{"params":{"pulses":"19 /root/input.csv 3"}}'
    Command failed: Invalid argument

    root@Omega:/# ubus call onion fast-gpio '{"params":{"pulses":"19,/root/input.csv,3"}}'
    Command failed: Invalid argument

    Do you know how the syntax for the ubus looks like for the pulses option?

    Thank you!



  • @Ricardo-Cassia : Oh okay, it wasn't clear to me that you were already using it correctly from the commandline.

    However, same thing applies here: The relevant ubus call is happening here: https://github.com/OnionIoT/onion-ubus/blob/master/onion-ubus.sh#L275. This is where it reads the parameters from the JSON thing. If you can figure out what the _ParseArgumentsObject functions parses exactly (located at /usr/lib/onion/lib.sh), you can figure out what JSON to give it so that the command string is created correctly.

    Edit: I've hacked my way around the parsing functions and atleast got the "set" to work right: ubus call onion fast-gpio '{"params":{"set":"8","1":""}}'. Ut just concatinates the keys and values of the JSON object together. However - if the key is empty, it is replaced by "-". The value can be empty however. Thus I can create the command string fast-gpio -u set 8 1 using this trick.. Characters like "/" and "." are replaced by "_" when they're the key string. Unfortunetly, these tricks doesn't seem to quite work for pulses. ubus call onion fast-gpio '{"params":{"pulses":"8","wave":"","1":""}}' just throws "invalid argument"..



  • Maximilian, thank you very much for your help.

    I experimented a little more and also concluded that the method doesn't work for the pulses option. However, I did find a work around.

    Instead of using the fast-gpio access through the ubus call (which would allow me access from anywhere), I created a 1-liner script that looks like this:

    fast-gpio pulses 19 $1 3

    and named it /root/gpio19

    Going back to the Onion Cloud, I chose the method launch-process, and as the command I set:

    /root/gpio19 /root/input.csv

    The response is:

    {
    "resp": "Command to launch in background: /root/gpio19 /root/1.on.csv"
    }

    and it actually does what was supposed to!

    By the way, I'm using this to create a middle man between the Internet and my RF controlled outlets. I can now develop apps or crontabs to turn things on and off through the house.


Log in to reply
 

Looks like your connection to Onion Community was lost, please wait while we try to reconnect.