Skip to content

Sort IP addresses problem #53

Description

@coriolan-v

Hello,

I'm running 10 Raspberry Pis on a specific router with addresses in 192.168.2.0/24. The raspberrys are attached to a piece of plywood so the physical order is important, however at startup of the router assigns random addresses to each Pi.

I'm adapting one of the examples to assign to each picture name the camera number (0 to 9) and an incremental number (0 to x) rather than the IP address. Example: 0-0.jpg, 1-0.jpg, 2-0jpg / 0-1.jpg, 1-1.jpg, 2-1.jpg, etc.

I can sort manually the Pis using the CPI command line (using Move), but when I try to do the same thing with a script it doesn't work: the script assign the number with the wrong cameras. The server.insert doesn't seem to work at all. Am I missing something?

Here's my code:

pic_number = 1
pictures_to_take = 1
loop = 10
cam_number = 10

import io
from compoundpi.client import CompoundPiClient

with CompoundPiClient() as client:
    client.servers.network = '192.168.2.0/24'
    client.servers.insert(0, '192.168.2.2')
    client.servers.insert(1, '192.168.2.9')
    client.servers.insert(2, '192.168.2.7')
    client.servers.insert(3, '192.168.2.3')
    client.servers.insert(4, '192.168.2.1')
    client.servers.insert(5, '192.168.2.12')
    client.servers.insert(6, '192.168.2.15')
    client.servers.insert(7, '192.168.2.8')
    client.servers.insert(8, '192.168.2.10')
    client.servers.insert(9, '192.168.2.4')

    assert len(client.servers) == 10
    client.resolution(1280, 720)
    
    while (pictures_to_take <= loop):

        client.capture()
       
        try:
            for addr, files in client.list().items():
                for f in files:
                    assert f.filetype == 'IMAGE'
                    print('Downloading from %s' % addr)
                    with io.open('%s-%s.jpg' % (cam_number, inc) , 'wb') as output:
                        client.download(addr, f.index, output)
                cam_number = cam_number + 1
        finally:
            client.clear()

        pictures_to_take = pictures_to_take + 1
        cam_number = 0
        pic_number = pic_number + 1

The output is not Picture 0 for IP 192.168.2.2, Picture 1 for 192.168.2.9, etc.
Instead it assigns the Picture 0 to the whatever the first IP that it finds (and it's not necessarily in ascending order).

Do you know what's going on?
Thanks very much for your help !

C.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions