Author Topic: Unable to connect to Losant via gateway  (Read 76 times)

bailejor

  • Newbie
  • *
  • Posts: 7
    • View Profile
Unable to connect to Losant via gateway
« on: June 18, 2017, 09:24:03 pm »
Hello,

I've had some serious difficulties with connecting to Losant and running the following code

Code: [Select]
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

I did everything listed in the "Getting started with MC-Things and Losant" guide and could not get the gateway or mc-module to connect to Losant. I tried it on both my home network and mobile hotspot. For both the gateway and module it says "Awaiting first connection to Losant".

Any tips?

Social Buttons


mc-T2

  • Administrator
  • Sr. Member
  • *****
  • Posts: 251
  • mc-Things! The opportunities are endless!
  • Location: Canada
    • View Profile
Re: Unable to connect to Losant via gateway
« Reply #1 on: June 26, 2017, 10:48:55 am »
Hi Bailejor,

Can you confirm that you have entered the correct information into the gateway?
Everything in Losant is case-sensitive so you need to ensure that you have entered the correct information into the gateway. This involves ensuring that the secret keys and access keys are entered correctly and you also need to enter the correct device ID.

I would suggest going through the getting started guide again and you can also check out this YouTube video that may help you out:

https://youtu.be/PVyjyIwcuUc

Let us know if that helps
Thanks
Need more mc-Modules, mc-Gateways or other mc-Things? Check out our product page: www.mcthings.com/products. mc-Development kits are available too!
Check out a live Dashboard using mcThings and Losant! Click here: https://goo.gl/ST43hB

bailejor

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Unable to connect to Losant via gateway
« Reply #2 on: June 26, 2017, 07:14:09 pm »
Thanks for your reply. I did so a number of times. I also just attempted to get MQTT to work and I cannot get the android client to connect to the server. The process seems straightforward enough. I have no idea what is going on.

mc-T2

  • Administrator
  • Sr. Member
  • *****
  • Posts: 251
  • mc-Things! The opportunities are endless!
  • Location: Canada
    • View Profile
Re: Unable to connect to Losant via gateway
« Reply #3 on: June 27, 2017, 09:26:51 am »
hmm, it is pretty straighforward. I find that the usual issue is information inserted into the wrong field and/or case sensitive mistakes.

Check out this video where we go through the whole process of setting up MQTT and sending information to an android client:

https://youtu.be/WfkQmg5P-3k

Need more mc-Modules, mc-Gateways or other mc-Things? Check out our product page: www.mcthings.com/products. mc-Development kits are available too!
Check out a live Dashboard using mcThings and Losant! Click here: https://goo.gl/ST43hB