Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

lambdaacademy/mim_iot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IoT for UPnP+

This repository contains instructions on how to setup a simple IoT network based on the UPnP+.

Table of Contents

Prerequisites

Setup UPnP Cloud Server (UCS)

This is an instruction on how to setup UCS using MongooseIM XMPP server.

  1. Run MongooseIM Docker container

    docker run -d -t -h mongooseim-1 --name mongooseim-1  -p 5222:5222 \
    -v `pwd`/mongooseim/config:/member mongooseim/mongooseim:rel-2.0

    The mongooseim/config directory contains MongooseIM configuration (ejabberd.cfg) file.

  2. Check that the server is running

    telnet localhost 5222

    Issue docker logs -f mongooseim-1 to see the server logs. Alternatively, start the container with -i option.

  3. (optional) Connect two users to see that the service works

    1. Install Psi XMPP client

    2. Register two users in the server

      docker exec -i -t mongooseim-1 /usr/lib/mongooseim/bin/mongooseimctl register user_1 localhost pass_1
      docker exec -i -t mongooseim-1 /usr/lib/mongooseim/bin/mongooseimctl register user_2 localhost pass_2
    3. Add an account for user_1 to PSI (General -> Account Setup -> Add)

      • XMPP Address: user_1@localhost
      • Password pass_1

    Note: Do not register a new user with PSI. Use the account that you've registered above.

    1. Change the user status to Online (Right Click on the user -> Status)

    2. Perform the two previous steps for user_2

    3. Make user_1 and user_2 friends

      1. Add user_2 to user_1 contact list (Right Click on user_1 -> Add Contact)

        • XMPP Address: user_2@localhost
      2. Authorize the invitations on both sides

    4. Send a chat message between the users

Setup UPnP Cloud Capable Device (UCCD)

This is an instruction for running UCCD as Nerves/Elixir application on Raspberry Pi.

Prepare

# fetch the dependencies
mix deps.get
# generate the ssh keys required to log in to the devices
./deps/erl_sshd/make_keys
# copy the host keys
mv priv apps/nerves_uccd/
# take a note of the generated in the CWD id_rsa and id_rsa.pub files
# that will be required at login into a device

Build for the host target

  1. Get dependencies and compile
cd apps/nerves_uccd/
# if the MIX_TARGET is not set it defaults to "host""
mix do deps.get, compile
  1. Run
iex -S mix

After you have completed these steps you can go to the Connect to an XMPP server section and connect to the XMPP server.

Build for mim_iot_rpi target

  1. Get dependencies and compile
cd apps/nerves_uccd/
export MIX_TARGET=mim_iot_rpi
mix do deps.get, compile
  1. Build firmware for the board
mix firmware
# insert and SD card
mix firmware.burn
# insert the card into the Pi and start it - it will boot into the shell
  1. SSH-in
# go to the root directory of the project
cd ../..
# ssh into the device
ssh -p 2222 -i id_rsa $RPI_IP # if you have [zeroconf] then use raspberrypi.local
# the id_rsa file was generated in the Prepare ssh step
  1. Start Elixir shell
'Elixir.IEx.CLI':local_start().

Connect to an XMPP server

Connect to the XMPP server using of the accounts created in the Setup UPnP Cloud Server (UCS) section.

To see the presences "flying" enable the XML console in the PSI for the user account you're using to log in.

alias Romeo.Connection, as: Conn
alias Romeo.Stanza
# the host is the IP address the UCS is listening on
opts = [jid: "user_1@localhost", password: "pass_1", host: "localhost"]
{:ok,pid} = Conn.start_link opts
Conn.send pid, Romeo.Stanza.presence
flush() # it will reveal XMPP messages being received from the server

In the aforementioned console you should see the presence being broadcasted by the server on the behalf of the resource that you've just connected:

<presence from="user_1@localhost/9C8A435B9A7118081493384264818216" xml:lang="en" to="user_1@localhost/szm-mac"/>

UcaLib

See apps/uca_lib which a library supporting UPnP+ steps.

SampleApp

See apps/sample_app which is a sample app implementing UPnP Contorl Point with a UI.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published