Adafruit IO (MQTT) and Servo

Hi guys,

I am still trying to understand MQTT and Arduino in general.

I am having difficulty in rotating my servo using MQTT. I can receive a value let's say like 20. How do I take that value and input it into my servo?

Thanks a lot.

(deleted)

spycatcher2k:
You read the value & servo.write it!

But without posting your code, this is as specific as it gets!

Hi, apologies for not sharing the code earlier. Please find it below:

#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include <ESP8266WiFi.h>

#include <Servo.h>

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME  "abdullahamir"
#define AIO_KEY  "xx"
WiFiClient client;

Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

Adafruit_MQTT_Subscribe servo = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/servo");
Servo servo_0;

boolean MQTT_connect();

boolean MQTT_connect() {  int8_t ret; if (mqtt.connected()) {    return true; }  uint8_t retries = 3;  while ((ret = mqtt.connect()) != 0) { mqtt.disconnect(); delay(2000);  retries--;if (retries == 0) { return false; }} return true;}

void setup()
{
  servo_0.attach(0); // attaches the servo to GPIO 01 port. 

Serial.begin(9600);

  mqtt.subscribe(&servo);
  WiFi.disconnect();
  servo_0.write(0);
  delay(0);
  delay(3000);
  Serial.println("START");
   WiFi.begin("Flat.403","502995361");
  while ((!(WiFi.status() == WL_CONNECTED))){
    delay(300);
    Serial.print("..");

  }
  Serial.println("Connected");
  Serial.println("Your IP is");
  Serial.println((WiFi.localIP().toString()));


}


void loop()
{

    if (MQTT_connect()) {
      Adafruit_MQTT_Subscribe *subscription_name;
      while ((subscription_name = mqtt.readSubscription(5000))) {
        if (subscription_name == &servo) {
          Serial.println(((char *)servo.lastread));

        }

      }

    }

}

Do I need to do something with last read? Not sure here kind of lost.

Thanks a lot for your help.

bump anybody?

abdullahamir:
bump anybody?

Do NOT bump a post with no additional information.

The code you posted does something. You haven't said WHAT your code does, or WHAT you get from the MQTT server, and NOWHERE have you tried to apply that to the servo.