Author Topic: Connection Problem  (Read 1817 times)

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Connection Problem
« on: July 20, 2016, 11:44:09 am »
Just Got my MC Modules etc. and set up. Downloaded all the latest versions, and updated firmware. See screenshot.


Had all sorts of problems connecting to a test module with the gateway hard wired (Ethernet), but beacons showed OK. So I changed to WiFi and moved everything close together (hard wired Ethernet is in the basement, so I though distance may be a factor). RSSI was showing 177 (what units? not standard db units anyway).

Now I can connect (occasionally), so I modified the temperature example (which is incomplete by the way), and set MQTT publishing to my MQTT broker (mosquitto) every 1 minute. This sort of worked (ie it published every 5 minutes or so).

I added UID and uptime, and again it sort of worked. Downloaded to flash RAM, and now it doesn't work at all. Does not publish, and will not connect. Device is 000111BC.

Green LED flashes immediately followed by red LED every 5 seconds. Beacon updates, and I can see it in devices (see screenshot). I assume the module is resetting (hence red led flashes every 5 seconds), but I can't connect to try to reload the program/script.

I have tried another test module, and that sort of seems to work (works in "run" but when embedded publishes every so often - misses some - and uptime is always 0). I can connect to this module (000111C2).

How can I recover the module that refuses to connect? is there a "factory reset" procedure or something? I have re flashed the mcModule code via the OTA updater (that works) but still no luck connecting.

Is this module toast? ???

Share on Facebook Share on Twitter


helge

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Connection Problem
« Reply #1 on: July 20, 2016, 12:39:30 pm »
Quote
How can I recover the module that refuses to connect? is there a "factory reset" procedure or something? I have re flashed the mcModule code via the OTA updater (that works) but still no luck connecting.

Same here. I bricked one of my modules, I guess it was some i2c code in the Boot event ;(

mc-Abe

  • Full Member
  • ***
  • Posts: 167
    • View Profile
    • mc-Things
Re: Connection Problem
« Reply #2 on: July 20, 2016, 12:45:17 pm »
Could you guys share a code snippet that you think is breaking your modules? I can try to reproduce the problem and fix it.

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Connection Problem
« Reply #3 on: July 20, 2016, 12:49:41 pm »
This is what I'm doing

Code: [Select]
//
// This example logs the mc Unique IDentifier (mcUID) and the Temperature
// to MQTT.
//

Class Temperature
   
    Shared mcUIDString As String
    Shared Event Boot()
        mcUIDString = Device.mcUID().ToString()
    End Event
   
    Shared Event GetTemp() RaiseEvent Every 1 Minutes
        LedGreen = True
       
        Dim TempC As Float = TempSensor.GetTemp
        Dim Temppayload As ListOfByte = New ListOfByte()
       
        Temppayload.Add(TempC.ToString)
       
        Lplan.Publish("MCThings/" + mcUIDString + "/Temperature", Temppayload)
       
        LedGreen = False
    End Event
   
    Shared Event GetUptime() RaiseEvent Every 1 Minutes
        //LedRed = True
       
        Dim uptime As Integer = Device.Uptime()
        //Dim uptimeString As String = uptime.ToString()
        Dim Uptimepayload As ListOfByte = New ListOfByte()
       
        Uptimepayload.Add(uptime.ToString)
       
        Lplan.Publish("MCThings/" + mcUIDString + "/Uptime", Uptimepayload)
       
        //LedRed = False
    End Event
   
    //Shared Event CheckVoltage() RaiseEvent Every 2 Days
    Shared Event CheckVoltage() RaiseEvent Every 2 Minutes
        Dim BattVolt As Short = Device.BatteryVoltage
        Dim Battpayload As ListOfByte = New ListOfByte()
        Battpayload.Add(BattVolt.ToString)
        Lplan.Publish("MCThings/" + mcUIDString + "/BatteryVoltage", Battpayload)
        //If BattVolt < 2200 Then
        //Lplan.IFTTT("YOURIFTTTKETHERE", "ProductionRoomBattery/YOURTOPICHERE")
        //Else
       
        //End If
       
    End Event
End Class

I think it's the
Code: [Select]
Uptimepayload.Add(uptime.ToString) that is the problem, as the one module I have that is working keeps resetting, but does publish from time to time. (that's why uptime is always 0).

I'm currently stuck in debug mode - so as soon as I get out of that I'll revert to the two step assignment and see if that fixes the reset.

mc-Abe

  • Full Member
  • ***
  • Posts: 167
    • View Profile
    • mc-Things
Re: Connection Problem
« Reply #4 on: July 20, 2016, 12:50:46 pm »
Thanks Nick_W. I am going to test this right away and see what I can find.

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Connection Problem
« Reply #5 on: July 20, 2016, 01:03:28 pm »
This works in run mode, but causes resets in embed mode.

Code: [Select]
//
// This example logs the mc Unique IDentifier (mcUID) and the Temperature
// to MQTT.
//

Class Temperature
   
    Shared mcUIDString As String
    Shared Event Boot()
        mcUIDString = Device.mcUID().ToString()
    End Event
   
    Shared Event GetTemp() RaiseEvent Every 1 Minutes
        LedGreen = True
       
        Dim TempC As Float = TempSensor.GetTemp
        Dim Temppayload As ListOfByte = New ListOfByte()
       
        Temppayload.Add(TempC.ToString)
       
        Lplan.Publish("MCThings/" + mcUIDString + "/Temperature", Temppayload)
       
        LedGreen = False
    End Event
   
    Shared Event GetUptime() RaiseEvent Every 1 Minutes
        //LedRed = True
       
        Dim uptime As Integer = Device.Uptime()
        Dim uptimeString As String = uptime.ToString()
        Dim Uptimepayload As ListOfByte = New ListOfByte()
       
        Uptimepayload.Add(uptimeString)
       
        Lplan.Publish("MCThings/" + mcUIDString + "/Uptime", Uptimepayload)
       
        //LedRed = False
    End Event
   
    //Shared Event CheckVoltage() RaiseEvent Every 2 Days
    Shared Event CheckVoltage() RaiseEvent Every 2 Minutes
        Dim BattVolt As Short = Device.BatteryVoltage
        Dim Battpayload As ListOfByte = New ListOfByte()
        Battpayload.Add(BattVolt.ToString)
        Lplan.Publish("MCThings/" + mcUIDString + "/BatteryVoltage", Battpayload)
        //If BattVolt < 2200 Then
        //Lplan.IFTTT("YOURIFTTTKETHERE", "ProductionRoomBattery/YOURTOPICHERE")
        //Else
       
        //End If
       
    End Event
End Class

It will publish, but resets every minute or so (so uptime is 0). Works fine in debug though. the difference is in lines 30-33 (two step). Will continue to investigate.

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Connection Problem
« Reply #6 on: July 20, 2016, 01:27:53 pm »
is there a version of the module .bin file that will erase the flash ram? I can perform OTA updates just fine (so boot loader is working), but whatever is in flash is resetting the module, so I can't connect.

A factory reset .bin would be very useful in unbricking these modules.

helge

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Connection Problem
« Reply #7 on: July 20, 2016, 02:18:27 pm »
Its strange, because the other module which has the same code in a ButtonPressed event works.

Code: [Select]
Class TSL2561Example
    Shared luminosity As TSL2561
    Shared _init As Boolean
   
    Shared Event Boot()
        luminosity = New TSL2561(TSL2561.TSL2561_ADDR_FLOAT)
        _init = luminosity.Begin()
    End Event
   
    Shared Event Report() RaiseEvent Every 30 Seconds
        Dim payload As ListOfByte = New ListOfByte
        Dim payString As String = ""
       
        If _init = True Then
            LedRed = True
            payString = "1"
        Else
            LedRed = False
            payString = "0"
        End If
        payload.Add(payString)
        Lplan.Publish("mcThings/TSL2561Example/Init", payload)
        Thread.Sleep(10000)
        Thread.ClearHardwareEvent()
        LedRed = False
    End Event
End Class

=================================================================
Class TSL2561
 Public Sub New(addr As Byte)
        gI2C = I2c.Create(I2C_SPEED, Pin.SCL, Pin.SDA, addr)
        gAddr = New ListOfByte()
        gData = New ListOfByte()
        _integration = TSL2561_INTEGRATIONTIME_13MS
        _gain = TSL2561_GAIN_16X
    End Sub
   
    Public Function Begin() As Boolean
        Dim dataByte As Byte
        dataByte = ReadSingleByte(TSL2561_REGISTER_ID)
        dataByte = dataByte & 0x0a
        If (dataByte > 0) Then
            SetTiming(_integration)
            SetGain(_gain)
            _initialized = True
            Disable()
            Return True
        Else
            Return False
        End If
.
.
.
    End Function

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Connection Problem
« Reply #8 on: July 20, 2016, 02:22:08 pm »
The code I have works in debug mode, not if you embed it to flash ram. Did you try embedding it?

helge

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Connection Problem
« Reply #9 on: July 20, 2016, 02:27:24 pm »
Quote
The code I have works in debug mode, not if you embed it to flash ram. Did you try embedding it?

jep. I didn't try it in debug mode. It works if the i2c class is initialized in the ButtonPressed event. My boot module sends no beacon nothing, but as you said firmware upgrade is possible.

mc-Abe

  • Full Member
  • ***
  • Posts: 167
    • View Profile
    • mc-Things
Re: Connection Problem
« Reply #10 on: July 20, 2016, 02:35:52 pm »
@Nick_W
I have tracked down your problem. I am creating a new release that should address your issue. Will be a few minutes.

@helge
I cannot try your project as I don't have the whole code but maybe the issues addressed here will help you as well.

mc-Abe

  • Full Member
  • ***
  • Posts: 167
    • View Profile
    • mc-Things
Re: Connection Problem
« Reply #11 on: July 20, 2016, 02:52:28 pm »
New version just went up. Could you guys try v0.7-361 of the module to see if that fixes your problem. Also we will be adding a feature in the mc-OTA to be able to erase the script.

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Connection Problem
« Reply #12 on: July 20, 2016, 03:10:32 pm »
OK, progress! :)

Not getting the same resets as before. Good module seems to be reporting more normally now.

Bricked module also does not reset as before, and I did get it to connect! However when I tried downloading my new code, the whole mcStudio UI froze until I removed the battery.

Trying to reconnect again (but it's difficult...).

I'll let you know if I succeed, but this is good progress...

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Connection Problem
« Reply #13 on: July 20, 2016, 03:19:07 pm »
I may have spoken too soon.

Just restarted mcStudio, and now I get nothing, no beacons - cannot see the modules at all. Restarting the gateway, mcStudio etc, see if anything shows up. Good module is still reporting via MQTT (not every minute, misses one or two - but it's alive).

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Connection Problem
« Reply #14 on: July 20, 2016, 03:26:48 pm »
Success!  ;D

After a complete restart of everything I managed to get everything back, beacons MQTT reporting etc. Connected to the bricked module and successfully downloaded working code, and it is now reporting via MQTT also!

Thank you for the quick response (and fix).

On now to the next problem....