.. _remote-weather-stations: Remote Weather Stations *********************** Connecting to another host located elsewhere on the Internet is normally a difficult proposition. This alludes to scenarios such as connecting from a company headquarters to a remote weather station, or from a distribution centre to a delivery truck. For reasons like public vs private IP addresses and firewalls, this class of network messaging is generally a non-starter. With pub-sub networking, exchanging messages with a remote weather station is as easy as exchanging messages with a process on the same host. There is some initial setup required and response times are much reduced, but at code level there is no difference. For pub-sub networking across the Internet, **ansar-connect** provides the fourth and final piece of infrastructure as a cloud service. The ansar CLI incorporates a set of related sub-commands that can complete configuration in a few minutes. On completion there is a new piece of infrastructure dedicated to your networking, running in the cloud. This guide extends on the areas covered in :ref:`a-networked-laboratory`. It uses those same materials and deploys another group of devices into a new host and LAN; * a laptop tethered to a smartphone, * an SBC with cellular connectivity, e.g. a Raspberry Pi. * or a desktop at a different physical site. Internet connectivity is a requirement at both ends. Initial setup of the deployment requires the following commands on the new host; .. code:: $ cd $ git clone https://github.com/mr-ansar/a-networked-laboratory.git $ cd a-networked-laboratory $ python3 -m venv .env $ source .env/bin/activate $ pip3 install ansar-connect pyinstaller .. note:: For a bare minimum demonstration of messaging across the Internet, refer to :ref:`this ` section. Finding Devices On The Internet =============================== Configuration of Internet messaging is a progression of the procedures already presented in :ref:`connecting-groups-of-processes` and :ref:`connecting-hosts-on-a-lan`. This first part of the configuration is performed at the central location, i.e. where the ``networked-laboratory`` is running. It results in a connection between the **ansar-lan** service (``--connect-scope=LAN``) and the cloud; .. code:: $ cd <../a-networked-laboratory> $ source .env/bin/activate $ ansar signup .. $ ansar account --show-identities + Account Acme Ltd (92fbdbcd-bf71-42f1-9f14-0b2d65f44603) + + Number of logins: 4 + + Number of directores: 4 + + Number of relays: 32 + + Logins (1) + + + Errol (0de79772-86ca-4a74-b6ca-dac9b46487d1) + + + + Login email: e.flynn@gmail.com + + + + Family name: Errol + + + + Given name: Flynn + + + + Nick name: + + + + Honorific: Mr + + Directories (1) + + + Ansar Networking/TESTING (64a32c2a-11dc-4f41-b45c-1dd351707491) + + + + Number of tokens: 4 + + + + Connected routes: 64 + + + + Messages per second: 8192 + + + + Bytes per second: 65536 + + + + Exported token (0) $ ansar directory --directory-id=64a32c2a-11dc-4f41-b45c-1dd351707491 --export --access-name=laboratory --export-file=laboratory.access $ ansar network --connect-scope=LAN --connect-file=laboratory.access $ ansar network + WAN Ansar Networking/TESTING + LAN 192.168.1.176:32177 + HOST 127.0.0.1:32177 + GROUP 127.0.0.1:45489 Details within the output will vary according to the information supplied to :ref:`ansar signup `. Passwords should contain at least 12 characters and include alphas, digits and at least one symbol. All communications with **ansar-wan** are encrypted using public key cryptography, as are all subsequent messaging sessions. * :ref:`ansar signup ` - create an online account, * :ref:`ansar account ` - display all available information about the new account, * :ref:`ansar directory ` - request an access file for the specified directory, * :ref:`ansar network ` - connect the local **ansar-lan** to the cloud. The :ref:`ansar directory ` command requests the creation of an access file. The ``directory-id`` is copy/pasted from the output of the :ref:`ansar account ` command and the result is a file called ``laboratory.access``. This file contains the information needed to make a runtime connection to the cloud entity and should be treated as security sensitive. Once the above commands are completed successfully, all the pub-sub software on the LAN is part of a private WAN. Local calls to :func:`~.subscribe` may match remote calls to :func:`~.publish`. Publishing Devices Over The Internet ==================================== This second part of the configuration process is performed on the new host. Deploy the devices with the following commands; .. code:: $ cd <../a-networked-laboratory> $ source .env/bin/activate $ make remote-devices pyinstaller --onefile --hidden-import=_cffi_backend --log-level ERROR -p . networked-laboratory.py pyinstaller --onefile --hidden-import=_cffi_backend --log-level ERROR -p . strain_device.py pyinstaller --onefile --hidden-import=_cffi_backend --log-level ERROR -p . temperature_device.py pyinstaller --onefile --hidden-import=_cffi_backend --log-level ERROR -p . `which ansar-group` ansar create ansar deploy dist ansar add strain_device --count=8 ansar add temperature_device --count=8 $ ansar network devices + GROUP 127.0.0.1:45489 To connect the devices to the cloud; .. code:: $ cd <../a-networked-laboratory> $ source .env/bin/activate $ ansar login .. $ ansar account --show-identities + Account Acme Ltd (92fbdbcd-bf71-42f1-9f14-0b2d65f44603) + + Number of logins: 4 + + Number of directores: 4 + + Number of relays: 32 + + Logins (1) + + + Errol (0de79772-86ca-4a74-b6ca-dac9b46487d1) + + + + Login email: e.flynn@gmail.com + + + + Family name: Errol + + + + Given name: Flynn + + + + Nick name: + + + + Honorific: Mr + + Directories (1) + + + Ansar Networking/TESTING (64a32c2a-11dc-4f41-b45c-1dd351707491) + + + + Number of tokens: 4 + + + + Connected routes: 64 + + + + Messages per second: 8192 + + + + Bytes per second: 65536 + + + + Exported token (1) + + + + + laboratory $ ansar directory --directory-id=64a32c2a-11dc-4f41-b45c-1dd351707491 --export --access-name=station --export-file=station.access $ ansar network devices --connect-scope=GROUP --connect-file=station.access $ ansar network devices + WAN Ansar Networking/TESTING + GROUP 127.0.0.1:45489 The :ref:`ansar login ` command is used to access the existing account. Output of the :ref:`ansar account ` command now includes a reference (i.e. ``laboratory``) to the access file created in the first part of the configuration. The remaining commands are similar to the first part of the configuration, except that the :ref:`ansar network ` command is used to connect the *group* to the cloud, missing out the **ansar-host** and **ansar-lan** services. Where other groups of processes are unlikely to be deployed onto a host and the host is unlikely to joined by other hosts, there is some efficiency in omission of the related services. Starting the devices remains the same. To observe the immediate integration of the new devices, view the logs from one of the local devices; .. code:: $ cd <../a-networked-laboratory> $ source .env/bin/activate $ make start-devices $ ansar log temperature_device-0 04:03:02.541 + <0000000a>SocketSelect - Created by <00000001> 04:03:02.541 < <0000000a>SocketSelect - Received Start from <00000001> 04:03:02.541 > <0000000a>SocketSelect - Sent SocketChannel to <00000001> 04:03:02.541 + <0000000b>PubSub[INITIAL] - Created by <00000001> 04:03:02.542 < <0000000b>PubSub[INITIAL] - Received Start from <00000001> 04:03:02.542 + <0000000c>lock_and_hold - Created by <00000001> 04:03:02.542 > <0000000c>lock_and_hold - Sent Ready to <00000001> 04:03:02.543 + <0000000d>node_vector - Created by <00000001> 04:03:02.543 ~ <0000000d>node_vector - Executable "/home/buster/a-networked-laboratory/.ansar-home/bin/temperature_device" as node process (774827) 04:03:02.543 ~ <0000000d>node_vector - Working folder "/" .. 04:03:02.545 > <0000000f>ConnectToDirectory[PENDING] - Sent CancelTimer to <00000003> 04:03:02.545 > <0000000f>ConnectToDirectory[PENDING] - Sent UseAddress to <0000000e> 04:03:02.545 < <0000000e>ServiceDirectory[NORMAL] - Received ServiceListing from <00000011> 04:03:02.545 ~ <0000000e>ServiceDirectory[NORMAL] - Added listing "device-temperature-polled-36b3dcaa-f49a-4f6e-b98e-e8fe756813a4" 04:03:02.545 < <0000000e>ServiceDirectory[NORMAL] - Received UseAddress from <0000000f> 04:03:02.545 > <0000000e>ServiceDirectory[NORMAL] - Sent PushedDirectory to <00000012> .. 04:03:02.580 > <0000000a>SocketSelect - Forward OpenLoop to <00000011> (from <00000014>) 04:03:02.580 < <00000011>PublishingAgent[READY] - Received OpenLoop from <00000014> 04:03:02.580 + <00000015>PublisherLoop[INITIAL] - Created by <00000011> 04:03:02.580 < <00000015>PublisherLoop[INITIAL] - Received Start from <00000011> 04:03:02.580 > <00000015>PublisherLoop[INITIAL] - Sent LoopOpened to <00000014> 04:03:02.580 > <00000015>PublisherLoop[INITIAL] - Forward Delivered to <00000010> (from <00000014>) 04:03:02.580 < <00000010>temperature_device - Dropped Delivered from <00000014> 04:03:02.580 < <00000014>SocketProxy[NORMAL] - Received LoopOpened from <00000015> 04:03:04.223 > <0000000a>SocketSelect - Forward Enquiry to <00000010> (from <00000014>) 04:03:04.223 < <00000010>temperature_device - Received Enquiry from <00000014> 04:03:04.223 > <00000010>temperature_device - Sent TemperatureSample to <00000014> 04:03:04.223 < <00000014>SocketProxy[NORMAL] - Received TemperatureSample from <00000010> 04:03:06.045 < <00000013>wandering_float - Received T1 from <00000003> 04:03:06.045 > <00000013>wandering_float - Sent StartTimer to <00000003> 04:03:06.226 > <0000000a>SocketSelect - Forward Enquiry to <00000010> (from <00000014>)