# Problem Connecting to Losant with mcThings

**URL:** <https://forums.losant.com/t/problem-connecting-to-losant-with-mcthings/534>\
**Category:** Help\
**Created:** [June 27, 2017, 2:04am UTC](https://forums.losant.com/t/problem-connecting-to-losant-with-mcthings/534 "2017-06-27T02:04:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jordan\_Bailey](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@Jordan\_Bailey](https://forums.losant.com/u/Jordan_Bailey)\
**Post date:** [June 27, 2017, 2:04am UTC](https://forums.losant.com/t/problem-connecting-to-losant-with-mcthings/534/1 "2017-06-27T02:04:21Z")

</div>

Hello,

I’ve been attempting to run the magnetic reed switch code and the getting started with Losant guide. I’ve tried it multiple times, made sure all case is accurate etc but I cannot get the modules/gateway to connect to Losant. Here is the guide I’m referencing: [https://www.losant.com/blog/getting-started-with-mc-things-and-losant](https://www.losant.com/blog/getting-started-with-mc-things-and-losant)

Here is the code:

```auto
    Class LosantDoor
  
  
    // Device ID of Peripheral in Losant
    Const LosantDeivceId As String = "594445eb57dcc600060018d5"
    // MQTT topic in Losant
    Const LosantTopic As String = "losant/" + LosantDeivceId + "/state"
  
    Shared _doorState As String
    Shared _doorcount As Integer
  
    Shared Event Boot()
        _doorState = "Open"
        _doorcount = 0
    End Event
  
    Shared Event ReedSwitchChanged()
        'debounce interrupt
        Thread.Sleep(100000)
        Thread.ClearHardwareEvent()
        LedRed = True
        If ReedSwitch = True Then
            _doorState = "Open"   
            _doorcount = _doorcount + 1
        Else
            _doorState = "Closed"
        End If
        sendMQTTData()
        LedRed = False
    End Event
  
    Shared Event CheckSensors() RaiseEvent Every 60 Seconds 
        sendMQTTData()
    End Event
  
    Private Sub sendMQTTData() 
        Dim tempTMP102string As String = TempSensor.GetTemp().ToString()
        Dim battShort As Short = Device.BatteryVoltage()
        Dim battFloat As Float = battShort / 1000
        Dim battString As String = battFloat.ToString()
  
  
        // Create data JSON object 
        Dim dataJson As Json = New Json
        dataJson.Add("battery", battString)
        dataJson.Add("temperature", tempTMP102string)
        dataJson.Add("doorState", _doorState)
        dataJson.Add("doorCount", _doorcount)
  
  
        // Create Losant preferred JSON object
        Dim losantPayload As Json = New Json
        losantPayload.Add("data", dataJson)
  
        // Publish to Losant MQTT
        Lplan.Publish(LosantTopic, losantPayload.ToListOfByte)
  
    End Sub
  
End Class

```

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [June 27, 2017, 2:08pm UTC](https://forums.losant.com/t/problem-connecting-to-losant-with-mcthings/534/2 "2017-06-27T14:08:39Z")

</div>

Hi, Jordan!

If you go into your device, on the left you should see a panel called “Debug”. Then, scroll down and take a look at your connection log. It should look like this:

 ![](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/1X/deed9c26dd6b5fd89009487b55ebb0f8a247a8f8.png)

Are you seeing any connection attempts here? Generally, this is the first place I check.

I’m sure you may have done this, but, can you verify all your credentials are correct? For mc-Things, here is what that would be:

```auto
MQTT Server - broker.losant.com
MQTT Port - 1883
MQTT Username - Your Losant Access Key
MQTT Username - Your Losant Access Secret
MQTT ClientId - This is the Device ID of the gateway you created in Losant.

```

---

<div class="post-metadata">

**Author:** ![Jordan\_Bailey](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@Jordan\_Bailey](https://forums.losant.com/u/Jordan_Bailey)\
**Post date:** [June 27, 2017, 6:25pm UTC](https://forums.losant.com/t/problem-connecting-to-losant-with-mcthings/534/3 "2017-06-27T18:25:39Z")

</div>

Thanks for your reply. I see no connection logs. It appears to not be connecting at all. I’ve verified that all credentials are correct.

---

<div class="post-metadata">

**Author:** ![Jordan\_Bailey](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@Jordan\_Bailey](https://forums.losant.com/u/Jordan_Bailey)\
**Post date:** [June 27, 2017, 8:03pm UTC](https://forums.losant.com/t/problem-connecting-to-losant-with-mcthings/534/4 "2017-06-27T20:03:32Z")

</div>

I forced a state and it appears to be working after doing so. Thanks!

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [June 27, 2017, 8:19pm UTC](https://forums.losant.com/t/problem-connecting-to-losant-with-mcthings/534/5 "2017-06-27T20:19:41Z")

</div>

I’m happy it’s working! Just to make sure I understand your solution. Did you Force State in Losant? Or, did you just send state from the device without the door sensor connected?
