NebraLtd / hm-pktfwd

Helium Miner Packet Forwarder
https://nebra.io/hnt
MIT License
12 stars 25 forks source link

add check for spi bus config.txt line #20

Closed shawaj closed 3 years ago

shawaj commented 3 years ago

if you do not enable the correct SPI bus, the lora concentrator fails to start with the error message...

ERROR: [main] failed to start the concentrator

however this is not really particularly helpful as an error message in this instance.

Perhaps there should be a check to see if the SPI bus defined in the variant_definitions.py file is actually enabled.

We can do this by searching for it in /dev using something like:

ls /dev | grep -i spi_bus

where spi_bus is the SPIBUS that is declared in variant_definitions.py

shawaj commented 3 years ago

@vpetersson @robputt could you take a look at this shitty python code I have written and check if it looks ok

https://github.com/NebraLtd/hm-pktfwd/blob/4216b49f982690228fc1e361c4ff3550a5195808/files/configurePktFwd.py#L22-L26

I am also not sure if it makes sense to keep trying the rest of the code if the SPI bus is not available? Maybe it makes more sense for it to just kill the container if this fails?

I guess this whole repo could do with a rewrite in any case....

vpetersson commented 3 years ago

I don't think you can use pipes (|) like that when you shell out using os.popen(). Let's just rewrite this to native Python code instead, as there is really no reason to call on os.popen() at all when we can use native Python functions to interface with the file.

shawaj commented 3 years ago

@vpetersson it works 😂 but not saying it's a good way of doing it.

I don't think /dev is a file but maybe we can use:

if os.path.exists('/dev/' + spi_bus):
    print("SPI bus Configured Correctly") 
else: 
    print("ERROR: SPI bus not found!") 
shawaj commented 3 years ago

added in d29648e40d7d4c3d15389a425523ca45dd4c6350

let me know what you think @vpetersson

vpetersson commented 3 years ago

if os.path.exists('/dev/{}'.format(spi_bus)): should work, but i don't have a device to easily test this.

shawaj commented 3 years ago

@vpetersson will test it now

shawaj commented 3 years ago

Added in https://github.com/NebraLtd/hm-pktfwd/pull/22/commits/d624b84cb937873ce44b1ba95f14bc87aaeb5492 and works fine

shawaj commented 3 years ago

closing as this is added in now