-1

I'm trying to send files to a remote modem using unetstack. Right now i have the following python script:

from unetpy import *
import sys

if len(sys.argv) != 6:
    print("Usage: python3 ac_sender.py <source_ip_address> <port> <destination_address> <timeout(ms)> <filename>")
    sys.exit(1)

ip_address = sys.argv[1]
port = int(sys.argv[2])
node = int(sys.argv[3])
timeout = int(sys.argv[4])
file_name = sys.argv[5]

sock = UnetSocket(ip_address, port)
gw = sock.getGateway()

req = RemoteFilePutReq(to=node, filename=file_name)
resp = gw.request(req, timeout)
print(resp)

But it is not working.I execute the scrip and it ends when the timeout returns. The response is None. There are no logs on the side of the remote modems. And the file is not uploaded. And yes the system arguments are being set correctl What am i doing wrong?

  • 1
    In what way is it not working? Are you getting an error? Unexpected behavior? Something else? – larsks Jul 07 '23 at 19:35
  • any error ? are the sys.argv[] variables being set properly ? – jmvcollaborator Jul 07 '23 at 19:35
  • 1
    No errors, I execute the scrip and it ends when the timeout returns. The response is None. There are no logs on the side of the remote modems. And the file is not uploaded. And yes the system arguments are being set correctly – Guilherme Moreira Jul 07 '23 at 21:11

1 Answers1

2

Suppose you want to send a file from modem A to modem B. Ensure that you enable the remote functionality on destination modem B by using the command remote.enable=true. Once remote is enabled, you can utilize the Python class below to initiate the file transfer between the two modems.

from unetpy import *
import time

class SendFile:
    def __init__(self, sock, recipient, file, number_of_loops=1, sleep_between_loops=0):
        self.sock = sock
        try:
            self.file = file
            self.recipient = recipient
            self.number_of_loops = number_of_loops
            self.sleep_between_loops = sleep_between_loops
        except Exception as ex:
            print("\033[91m-E- failed to load signal file\033[0m")
            print(str(ex))
            exit()

    def id(self):
        print()
        print("\033[92m------------------------------------------------------\033[0m")
        print("\033[92mTask Type: SendFile\033[0m")
        print("\033[92mRecipient: {}\033[0m".format(self.recipient))
        print("\033[92mSending File: {}\033[0m".format(self.file))
        print("\033[92mNumber_of_loops: {}\033[0m".format(self.number_of_loops))
        print("\033[92mSleep_between_loops: {}\033[0m".format(self.sleep_between_loops))

    def exec_step(self):
        print()
        gw = self.sock.getGateway()
        remote = gw.agentForService(Services.REMOTE)
        remote.enable = True

        for i in range(0, self.number_of_loops):
            print()
            print("\033[94m-I- Sending a File remotely #{} {}\033[0m".format(i + 1, self.file))
            remote << RemoteFilePutReq(to=self.recipient, filename=self.file)
            if self.sleep_between_loops:
                print("\033[94m-I- Sleeping for {} seconds\033[0m".format(self.sleep_between_loops))
                time.sleep(self.sleep_between_loops)
            print("\033[92m------------------------------------------------------\033[0m")


if __name__ == "__main__":
    sock = UnetSocket("localhost", 1101)
    task = SendFile(sock, 31, "README.md")
    task.id()
    task.exec_step()

You can check the logs on remote by enabling subscribe remote.

Jay Patel
  • 1,374
  • 1
  • 8
  • 17