===== ITT Servo module ===== This laboratory is located in the office of ITT Group in Tallinn, Estonia. ==== Introduction ==== This laboratory can be used to practice controlling the servo motor attached to the controller. {{:en:iot:examples:servopicture2.jpg?300|}} ==== Prerequisites ==== For this laboratory, the student should understand basic MQTT concepts like topics, broker, subscribing and publishing. ==== Technical details ==== This laboratory consists of a servo with the add-on module attached to the ITT IoT controller module. === Sensors === This laboratory does not have any sensors. === Specifications ===
/*
* IoT Servo example
*
* This example subscribe to the "servo" topic. When a message received, then it
* change servo position
*
* Created 11 Sept 2017 by Heiko Pikner
*/
#include
#include
#include
//Pin definition for the Servo (D3)
#define SERVO_PIN D3
Servo myservo; // create servo object to control a servo
// Change the servo position (value between 0 and 180)
// mosquitto_pub -u test -P test -t "RL/esp-{ESP-ID}/servo" -m "51"
// = this calls servo motor to change position
void iot_received(String topic, String msg)
{
Serial.print("MSG FROM USER callback, topic: ");
Serial.print(topic);
Serial.print(" payload: ");
Serial.println(msg);
Serial.print("Servo: ");
Serial.println(msg);
myservo.write(msg.toInt());
}
// Function started after the connection to the server is established
void iot_connected()
{
Serial.println("MQTT connected callback");
// Subscribe to the topic "servo"
iot.subscribe("servo");
iot.log("IoT Servo example!");
}
void setup()
{
Serial.begin(115200);
Serial.println("Booting");
// Print json config to serial
iot.printConfig();
// Initialize IoT library
iot.setup();
myservo.attach(SERVO_PIN);
}
void loop()
{
// IoT behind the plan work, it should be periodically called
iot.handle();
delay(200);
}
==== Support ====
info@ittgroup.ee