rwilson504 / IoTPowerPhone

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IoT Power Phone

image

If you want to learn how to build other types of devices with Azure IoT and a Raspberry Pi check out this awesome simiulator which integrated with Azure IoT Service in real time. Raspberry Pi Azure IoT Online Simulator

Physical Buildout

I really wanted to make this device look like the bat phone from the 60's. I spend a lot of time at antique shops looks for old "direct" phone like you would use in a factory to call a specific location. Finally on one of my trips to Hocking Hills I found one. I wanted the device to ring and blink like the original so I wired up all up on a solder free breadboard. I first used a larger breadboard for testing them moved everything to a smaller one that installed inside the phone with double sided tape. I also spend a lot of time with Red Apple colordered spray paint.

The following articles helped me figure out the LED and buzzer elements:

Here is the pinout from the Raspberry Pi
image

Breadboard showing LED
image

Breakboard showing Buzzer
image

Final smaller breadboard installed inside phone
image

Overall view of the inside after installation was complete
image

Soooo much paint
image

Setup for Raspberry Pi with .Net Core

I used the scripted install to add .Net core onto the Raspberry Pi devices. Scripted Install

Download the files onto the device using wget
'''wget https://dot.net/v1/dotnet-install.sh'''

Run the following command from the terminal.
'''sudo bash dotnet-install.sh -c Current -InstallDir $HOME/.dotnet'''

This will ensure that every time you open a bash terminal dotnet will be available.
'''printf '\nexport DOTNET_ROOT=$HOME/.dotnet' >> .bashrc'''
'''printf '\nexport PATH=$PATH:$HOME/.dotnet' >> .bashrc'''

*NOTE: it is important to use the single quotes around these otherwise the variables will be expanded within the text file.

If you want to check to make sure the file was updated correctly you can run the following Cat .bashrc

Setting up the PowerPhone.service Variables

In order for the device to connect to Azure IoT central and listen for commands we need to create a service that runs on the Pi and is actively listenting. Details for enabling this service can be found in the How to Deploy section, here we will walk through the settings in the service file and where to get those values.

Name Value Description
IOTHUB_DEVICE_SECURITY_TYPE DPS The IoT Hub Device Provisioning Service is a helper service that enables just-in-time profiviions to the IoT hub. Do not change this value.
IOTHUB_DEVICE_DPS_ENDPOINT global.azure-devices-provisioning.net This is the gloabl endpoint for DPS provisioning, in this example there is no reason to change this value.
IOTHUB_DEVICE_DPS_ID_SCOPE In your IoT Central application, navigate to Permissions > Device connection groups. Make a note of the ID scope value. image
IOTHUB_DEVICE_DPS_DEVICE_ID power-phone Decide what you want to call this specific device. In this example I named the device power-phone. If you have multiple devices you may wan to also add in a number at the end of the name like power-power-01
IOTHUB_DEVICE_DPS_DEVICE_KEY You will generate this in the Azure Cloud Shell In your IoT Central application, navigate to Permissions > Device connection groups > SAS-IoT-Devices.

Make a note of the shared access signature Primary key value. image

Open the Azure Cloud Shell and run the following commands:

az extension add --name azure-iot
az iot central device compute-device-key --device-id <<device name you chose>> --pk <the SAS key you copied>

image

Copy and past the generated device key as the value for this attribute.

Additional references: Tutorial: Create and connect a client application to your Azure IoT Central application

How to Deploy

-Create a deployment folder on the Raspberry Pi

sudo mkdir /srv/PowerPhone

-Ensure your user owns the folder

sudo chown pi /srv/PowerPhone

-From the project folder run this command to publish the app self contained for linux. This will ensure all the depdencies are included for the linux platform.

dotnet publish -c Release -o /srv/PowerPhone -r linux-arm

-Open the PiService/PowerPhone.service file -Update the environment variables to match your device -Copy the file to the /lib/systemd/system

sudo cp /home/pi/IoTPowerPhone/PowerPhone/PiService/PowerPhone.service /lib/systemd/system

-Start the service and make sure there are no errors

sudo systemctl start PowerPhone

-Ensure that the service starts up on every reboot.

sudo systemctl enable PowerPhone

Create Canvas App and Flow

I also created a simple power app that would allow me to ring the phone manually. The call to the device is done through Power Automate using the Azure IoT Central connector.

-First create a simple Canvas app with a button. image

-Create a new Power Automate Flow which will be run when the button is clicked. Because the command I created is within the "Ringer" component of the devices, I chose the Run a component command activity. image

-Configure the activity based on your settings. The Device Id should match the device name you used in the PowerPhone.Service file. image

About


Languages

Language:C# 100.0%