Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:remotelab:itt:servo [2018/12/06 06:31] rim.puksen:iot-open:remotelab:itt:servo [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
-===== Servo module =====+===== ITT Servo module =====
 This laboratory is located in the office of ITT Group in Tallinn, Estonia. This laboratory is located in the office of ITT Group in Tallinn, Estonia.
  
Line 41: Line 41:
  
 ==== Hands-on labs ==== ==== Hands-on labs ====
-//List study scenarios (hands-on labs), linking to the Dokuwiki pages with hands-on labs descriptions (there should be a separate page for each scenario). Classify each scenario and refer to the target group using starting keywords+ 
-  * Beginners +=== Example code === 
-  * Undergraduates + 
-  * Masters +<code c> 
-  * Professionals +/
-Note, assume that more professional group automatically contains less professional onesNote - use language and as appropriate to the target group, i.e.:// + * IoT Servo example 
-<code> + * 
-  * Beginners: Elementary operations on the Arduino 2x16 LCD screen+ * This example subscribe to the "servo" topic. When a message received, then it 
-  * Undergraduates: Visualizing temperature and humidity on the remote screen+ * change servo position 
-  * Masters: Using power saving states to limit power consumption.+ * 
 + * Created 11 Sept 2017 by Heiko Pikner 
 + */ 
 + 
 +#include <Arduino.h> 
 +#include <Servo.h> 
 +#include <ittiot.h> 
 + 
 +//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); 
 +
 </code> </code>
 +
 ==== Support ==== ==== Support ====
-//Give some information on how to access help, how to get support in case of the trouble etc.//+info@ittgroup.ee
  
en/iot-open/remotelab/itt/servo.1544077899.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