# Homeyduino @ V2.0

**URL:** <https://community.homey.app/t/homeyduino-v2-0/6407>\
**Category:** Apps\
**Created:** [January 6, 2019, 6:08pm UTC](https://community.homey.app/t/homeyduino-v2-0/6407 "2019-01-06T18:08:53Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![Marlon](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marlon/32/3794_2.png) [@Marlon](https://community.homey.app/u/Marlon)\
**Post date:** [January 7, 2019, 4:28pm UTC](https://community.homey.app/t/homeyduino-v2-0/6407/11 "2019-01-07T16:28:33Z")

</div>

I recently converted a Homeyduino project to MQTT and a VirtualDevice. It was rather easy!

For you arduino project you can take a look at [PubSubClient](https://github.com/knolleary/pubsubclient)

Below you can take a excerpt of my code:

```
const char *mqttServer = "192.168.1.61";
const int mqttPort = 8883;
const char *mqttUser = "test";
const char *mqttPassword = "uno";

WiFiClientSecure espClient;
PubSubClient client(espClient);    
const char *motion_topic = "home/hallway/pir/motion";
const char *luminance_topic = "home/hallway/pir/luminance";

```

// after connecting to your wifi don’t forget to connect to the MQTT Server

```
if (!client.connected()) {
    client.setServer(mqttServer, mqttPort);
    client.setCallback(callback);
    Serial.print("Connecting to MQTT server "); Serial.print(mqttServer);
    while (!client.connected()) {
      if (client.connect(clientId.c_str(), mqttUser, mqttPassword ))
      {
        Serial.println("\tconnected");
      } else {
        delay(500);
        Serial.print(".");
      }
    }
  }

```

// After reading some sensor values publish the values

```
float lux = lightMeter.readLightLevel();
client.publish(luminance_topic, String(lux).c_str(), true);
client.publish(motion_topic, motionDetected ? "1": "0", true);

```

Then subscribe to topic and set Virtual Device capability

 ![PNG](https://us1.discourse-cdn.com/flex025/uploads/athom/original/2X/d/dec37136d6d4d2fbda292efd96e6990abfc057eb.jpeg)  
 ![PNG](https://us1.discourse-cdn.com/flex025/uploads/athom/original/2X/4/45c2dc8fcd085e4deab3d1e88315e91166060f4a.jpeg)

---

_[View the full topic](https://community.homey.app/t/homeyduino-v2-0/6407)._
