This is an old revision of the document!


U7: Controlling fan speed and servo angle via MQTT

In this scenario, you will learn how to remotely control fan speed using PWM and how to control servo angle using MQTT messages. This scenario is a practical extension to the scenario U4 where you learned, how to receive and handle MQTT messages.

Target group

Undergraduate / Bachelor / Engineering Students

Prerequisites

We assume you already know how to:

  • handle LCD screen to present information,
  • connect to the existing WiFi network: internal.IOT,
  • receive and handle MQTT messages using PubSubClient library
  • additionally we will ask you to install and use an MQTT client of your choice. We suggest using MQTT Spy, but any MQTT client that will let you subscribe to the MQTT messages is OK. You connect it to the public IP of the MQTT broker (see below).

MQTT broker present in the internal.IOT network is also visible under public address. So whenever you subscribe to the MQTT message using VREL node that is connected to the internal.IOT network, you may publish to it using other devices connected to the internal.IOT, i.e. other VREL node or if you're physically present at SUT in the IOT laboratory room 320, then you can connect your mobile and laptop to the internal.IOT network and use “internal” IP address. However, if you're in a remote location, you can access the same broker under public IP as stated in the node description. When you publish an MQTT message using public IP, it will be delivered to the subscribers in the private internal.IOT network as well. Mind, to access MQTT broker you need to use IP, user and password (applies to both public and private IPs of the MQTT Broker). Refer to the node documentation for the latest information.

Note - information present in source code samples can be not up-to-date - remember to refer to the VREL node documentation for the latest information on IPs, users and passwords for both internal.IOT network access and for the MQTT Broker.
Warning - physical servo range is ONLY between 0 and 90 degrees! Going over 90 degrees may cause a break to the equipment and you may be charged for repair!

Scenario

In this scenario, you will handle incoming MQTT messages (one for controlling fan, other for servo, opening and closing the flap. Parallelly you will present incoming messages on the LCD screen.

Result

You should be able to remotely control fan rotation speed and flap angle (0..90 degrees), observe connection status and incoming MQTT messages for your device on the LCD screen.

Start

Define some identifiers to separate and update AP's SSID and passphrase easily. To format lines for the LCD, we suggest using a char buffer of 20 characters (one full line) and some 2-3 integers for iterators and storing current PWM for servo and fan. Remember to declare the LCD control class in your code. You do not need to instantiate WiFi communication class - as you have only one interface here, it is singleton class you can refer directly using WiFi. Reading analogue input brings you an integer value.

Servo is controlled using GPIO pin D5 (GPIO14) while the fan is controlled using GPIO pin D8 (GPIO15). As servo we use is a small one, it is powered and controlled directly through the ESP8266 while in case of the FAN, it is controlled indirectly, using a transistor.

Legal range for the servo is 0…90 degree! Exceeding over 90 degrees may break the construction!
Valid range for controlling fan is 0 (stopped) till 4095 (full speed). Please note, characteristics are non-linear, so setting output 2047 does not mean that rotation speed nor airflow is half of the maximum.

Steps

Write some extra information if i.e. some steps are optional otherwise cancel this paragraph (but do not remove header).

Step 1

Describe activities done in Step 1.

Step n

Describe activities done in Step n.

Result validation

Provide some result validation methods, for self assesment.

FAQ

This section is to be extended as new questions appear.
When using the printed version of this manual please refer to the latest online version of this document to obtain the valid and up-to-date list of the FAQ. Provide some FAQs in the following form:
Question?: Answer.

en/iot-open/remotelab/sut/generalpurpose2/u7.1565524875.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0