mc-Things

mc-Products => mc-Module => Topic started by: Nick_W on July 20, 2016, 11:44:09 am

Title: Connection Problem
Post by: Nick_W 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.
(https://www.dropbox.com/s/1iyi65g4s1sqznj/Screenshot%202016-07-20%2012.26.25.png?dl=0)

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? ???
Title: Re: Connection Problem
Post by: helge 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 ;(
Title: Re: Connection Problem
Post by: mc-Abe 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.
Title: Re: Connection Problem
Post by: Nick_W 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.
Title: Re: Connection Problem
Post by: mc-Abe 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.
Title: Re: Connection Problem
Post by: Nick_W 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.
Title: Re: Connection Problem
Post by: Nick_W 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.
Title: Re: Connection Problem
Post by: helge 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
Title: Re: Connection Problem
Post by: Nick_W 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?
Title: Re: Connection Problem
Post by: helge 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.
Title: Re: Connection Problem
Post by: mc-Abe 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.
Title: Re: Connection Problem
Post by: mc-Abe 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.
Title: Re: Connection Problem
Post by: Nick_W 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...
Title: Re: Connection Problem
Post by: Nick_W 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).
Title: Re: Connection Problem
Post by: Nick_W 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....
Title: Re: Connection Problem
Post by: mc-Abe on July 20, 2016, 03:35:24 pm
Glad to hear it Nick_W. Keep the problems coming and we will do our best to keep up with fixing it.

We have added a sanity check for the script which consists of the device being able to successfully run for 10 minutes before something so awfully bad happens that it can only reboot to recover. If it cannot run for 10 minutes, it will invalidate the script before it reboots. This will give you at least 10 minutes to connect to the device which should be plenty of time.
Title: Re: Connection Problem
Post by: Nick_W on July 20, 2016, 03:46:01 pm
New (or maybe not) weird thing, don't know if this is related:

Now reporting via MQTT, it looks like the data is cached somewhere. I'm reporting uptime, battery voltage and temperature every minute, in 3 topics.

What happens is that the green LED flashes (indicating a report) every minute, but in MQTT, the values are published every 2 minutes, but for both reports - ie flash - no report, minute later flash - two reports (uptime shows correctly, which is why it looks like it's being cached).

see the output of my MQTT monitor below:

Code: [Select]
MCThings/70082/Uptime 600
MCThings/70082/BatteryVoltage 2907
MCThings/70082/Temperature 25.125000
MCThings/70082/Uptime 660
MCThings/70082/BatteryVoltage 2907
MCThings/70082/Temperature 25.062500
MCThings/70076/Uptime 480
MCThings/70076/BatteryVoltage 2875
MCThings/70076/Temperature 25.250000
MCThings/70076/Uptime 540
MCThings/70076/BatteryVoltage 2875
MCThings/70076/Temperature 25.187500
MCThings/70082/Uptime 720
MCThings/70082/BatteryVoltage 2907
MCThings/70082/Temperature 25.062500
MCThings/70082/Uptime 780
MCThings/70082/BatteryVoltage 2907
MCThings/70082/Temperature 25.000000
MCThings/70076/Uptime 600
MCThings/70076/BatteryVoltage 2875
MCThings/70076/Temperature 25.062500
MCThings/70076/Uptime 660
MCThings/70076/BatteryVoltage 2875
MCThings/70076/Temperature 25.000000
MCThings/70082/Uptime 840
MCThings/70082/BatteryVoltage 2907
MCThings/70082/Temperature 25.000000
MCThings/70082/Uptime 900
MCThings/70082/BatteryVoltage 2907
MCThings/70082/Temperature 25.000000
MCThings/70076/Uptime 720
MCThings/70076/BatteryVoltage 2875
MCThings/70076/Temperature 24.937500
MCThings/70076/Uptime 780
MCThings/70076/BatteryVoltage 2875
MCThings/70076/Temperature 24.937500

This is from two modules, one was the bricked one (now alive!). If you look at the report from module 70076 the last two reports (uptime 720 and 780) arrive at the same time  - but the uptime is 60 second apart, and the dual reports arrive at 2 minute intervals (event is set for 1 minute, and LED flash shows every minute).

Could the gateway be caching these? where would they be cached if they in fact are?

Any ideas?
Title: Re: Connection Problem
Post by: mc-Abe on July 20, 2016, 04:47:32 pm
The module attempts to connect to the gateway when you send a message but for a variety of reasons, the connection can be missed and then on the next connection interval it sends the messages that were queued up on the module. I saw the same behavior, it is suspect that it is somewhat repeatable to once every 2 minutes so we are investigating this.
Title: Re: Connection Problem
Post by: helge on July 21, 2016, 06:38:30 am
the new firmware didn't solve my issue. the module boots normally, red led blinks once then only one beacon is received and then it locks up. I have access to a nRF51 DK if that would be helpful.
Title: Re: Connection Problem
Post by: mc-Abe on July 21, 2016, 11:02:36 am
Could you provide me the code that you ran? I can see why it would do this.
Title: Re: Connection Problem
Post by: mc-Abe on July 26, 2016, 10:59:45 am
@helge
I looked over you code. I can't 100% test it since I don't have your device. However, I was wondering where you got the 0x1D slave address from? I don't see 0x1D as an option in the table in TSL2561 datasheet which I have attached here. Unless I am looking at the wrong table.

If this is the case, you will have a run-time error as you try to read data that never came back from the device. Did you ever try this in debug mode? You should have gotten a pop up that told you that.

Title: Re: Connection Problem
Post by: helge on July 26, 2016, 11:27:10 am
@mc-Abe

well the lockup occurs even if the i2c device is not connected any more. the module blinks red once and thats it. no beacon is sent. It's still possible to OTA flash it with the updater. can you please pm me the hex file to re-flash the mc-Module with nrfjprog?
Title: Re: Connection Problem
Post by: mc-Abe on July 26, 2016, 05:02:38 pm
The symptoms are consistent with what I described earlier. The run-time error exists even if you don't have a device connected. You try to read from the device and then index into an empty list object which causes a run-time error. When the device is not in debug mode and encounters a run-time error, it goes into debug mode. There is nothing it can do to recover so it sits there and waits for you to connect to it. This is why you do not see any more beacons. Beacons are not set in debug mode.

Just to note, I believe there was an issue with the mc-Gateway Host Processor and that is why you could not connect to your device. I just uploaded a new version that you should try. I have replicated your exact problem and I can connect to my device with mc-Studio and reprogram it.

Unfortunately I cannot give you the hex file for the module. In the near future we will have the ability to erase the script through the mc-OTA.

let me know if this fixes your problem.
Title: Re: Connection Problem
Post by: helge on August 04, 2016, 11:15:18 am
@mc-Abe

1) no, the connection to the module is still not working. In the meantime another module is also dead. OTA updates are still possible.
2) why does my code work within the ButtonPressed Event and bricked the mc-module in the Boot Event? Doesn't make sense.
3) hex file: read my in mc-Product General section here, which is still waiting for an official response here
Title: Re: Connection Problem
Post by: mc-Abe on August 04, 2016, 01:21:12 pm
1) Are you running v0.7-406 of the Gateway Host Processor? This will show up under LplanVersion in the Device dialogue in mcStudio. I tested this again and I am able to connect to the device running your code. Modified to Boot instead of on button pressed.

2) As I described, you have a run-time exception. The run-time exception causes the device to stop executing code and enter debug mode, waiting for a connection. When the code is in Boot, it runs immediately when device boots. But in button press it waits until you press the button, after you press the button the exception happens and the device stops executing code.

3) As I said earlier, Unfortunately I cannot share the hex with you. There is an OTA Updater release imminent that will allow you to erase the script.