Author Topic: Red LED blinks without reference in code  (Read 861 times)

millennial

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Red LED blinks without reference in code
« on: July 10, 2016, 07:04:19 pm »
Is it possible for the red LED to blink from the firmware while the battery is plugged in? I am not talking about when the battery is initially put in, but after the battery has been in for 40 seconds or more. My code does not use the LEDs.

Could this mean the battery is low? Or, is my code bugging out and the mc-module is doing a quick reboot?

Update: I think it may have something to do with the DateTime object (although it could possibly be the newly released JSON support, as I am working out of the example JSON project). More times than not, I am getting date data in MQTT subscribers as this: 2000-01-01T00:00:00+00:00 as opposed to the current time. Two points:

1) ISO strings are formatted as such in JavaScript: YYYY-MM-DDTHH:MM:SS.MMMZ There is no +
2) The fact that it is defaulting to the epoch of 2000 leads me to believe the code might be crashing with however mc-modules get the current time. This would actually be interesting to learn about from mc-things: How do mc-modules sync their clocks? Is it the mc-gateway's job?
« Last Edit: July 10, 2016, 07:26:55 pm by millennial »

Share on Facebook Share on Twitter


mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Red LED blinks without reference in code
« Reply #1 on: July 10, 2016, 08:54:05 pm »
Battery low does not do this. A reboot takes at least 5 seconds because that is the time the bootloader tries to connect to the dongle. What is blink frequency?

The gateway keeps time and the module get their time from the gateway. The gateway get its time from a internet time server.

Is the problem going away if you remove the datetime from your JSON string?


mc-Abe

  • Full Member
  • ***
  • Posts: 167
    • View Profile
    • mc-Things
Re: Red LED blinks without reference in code
« Reply #2 on: July 11, 2016, 12:24:01 am »
I will retest the JSON code to see if anything in the latest release has caused problems. It does appear that your module has not had a chance to synchronize it's time with a gateway. This is done once a day. I will look and see if there is a need for some retries to improve this function.

There is no official DateTime format for JSON. We have chosen to support the ISO 8601 format. This format has a few acceptable representations. We have chosen to support 3 of them:

YYYY-MM-DDTHH:MM:SSZ -> This is Zulu time or UTC time.
YYYY-MM-DDTHH:MM:SS -> Local time without time zone information which is not very useful unless you are talking to only services in your local time zone.
YYYY-MM-DDTHH:MM:SS+HH:MM -> Local time with time zone information.

The JSON string conversion is by default done using the local time with timezone information. At this time there is no way to tell the JSON class to use another time format. You can however convert a DateTime object to a string using .ToString("L") or .ToStirng("Z") to force local time without timezone or Zulu time representation. You can then add your string to your JSON object.
Like Like x 1 View List

millennial

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Red LED blinks without reference in code
« Reply #3 on: July 11, 2016, 11:02:27 am »
Battery low does not do this. A reboot takes at least 5 seconds because that is the time the bootloader tries to connect to the dongle. What is blink frequency?

The gateway keeps time and the module get their time from the gateway. The gateway get its time from a internet time server.

Is the problem going away if you remove the datetime from your JSON string?



I ran the mc-module for a few events in my code (see below) and saw the red light blink, almost like I inserted the battery, at the following times:

11:27:10
11:27:34
11:28:00
11:28:23
11:28:49
11:29:18 (should have happened, but I didn't see it go red)
11:29:35

The green light will go on (first event), 10 seconds later go off (second event), ~10 seconds later the red light will flicker, and then the green light will go on again. The Losant device rarely has its state updated (though it has worked sometimes).

I will try removing datetime soon.

Code: [Select]
Class JsonExample
   
    Const DeviceId As String = "577144f8af5318010042c29b"
    Const PublishTopic As String = "losant/" + DeviceId + "/state"
   
    Shared Event Report() RaiseEvent Every 10 Seconds
       
        // Create date object
        Dim jDate As Json = New Json
        Dim date As DateTime = DateTime.Now
        jDate.Add("$date", date)
       
        // Create data object
        Dim jData As Json = New Json
        Dim temperature As Float = TempSensor.GetTemp
        jData.Add("temperature", temperature.ToInteger)
       
        // Create state object
        Dim jState As Json = New Json
        jState.Add("time", jDate)
        jState.Add("data", jData)
       
        Lplan.Publish(PublishTopic, jState.ToListOfByte)
       
        LedGreen = Not LedGreen
    End Event
   
End Class

mc-Abe

  • Full Member
  • ***
  • Posts: 167
    • View Profile
    • mc-Things
Re: Red LED blinks without reference in code
« Reply #4 on: July 11, 2016, 11:18:13 am »
I have tested this and it seems to be working as expected. Note that the device synchronizes its time with the gateway on power up and then once a day. However, if the time sync request gets in before the gateway has gotten a time from the SNTP server you might get uptime from epoch, which I think is what is happening in your case.
« Last Edit: July 11, 2016, 11:35:41 am by mc-Abe »

millennial

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Red LED blinks without reference in code
« Reply #5 on: July 11, 2016, 11:35:56 am »
Tried again with the two following pieces of code and I am still getting red blinks as though a device reset happened. Now I am thinking it is just something with the recent MQTT bug fixes.

Code: [Select]
Class JsonExample
   
    Const DeviceId As String = "577144f8af5318010042c29b"
    Const PublishTopic As String = "losant/" + DeviceId + "/state"
   
    Shared Event Report() RaiseEvent Every 10 Seconds
       
        // Create data object
        Dim jData As Json = New Json
        Dim temperature As Float = TempSensor.GetTemp
        jData.Add("temperature", temperature.ToFloat)
       
        // Create state object
        Dim jState As Json = New Json
        jState.Add("data", jData)
       
        Lplan.Publish(PublishTopic, jState.ToListOfByte)
        Lplan.Publish("test" + PublishTopic, jState.ToListOfByte)
       
        LedGreen = Not LedGreen
    End Event
   
End Class

Code: [Select]
Class JsonExample
   
    Const DeviceId As String = "577144f8af5318010042c29b"
    Const PublishTopic As String = "losant/" + DeviceId + "/state"

    Shared Event Report() RaiseEvent Every 10 Seconds

        Dim payload As ListOfByte = New ListOfByte
        Dim payloadstring As String
        Dim temp As Float = TempSensor.GetTemp()
        Dim tempstring As String = temp.ToString()
       
        LedGreen = Not LedGreen
       
        payloadstring = "{\x22data\x22:{"
        payloadstring = payloadstring + "\x22temperature\x22:\x22" + tempstring + "\x22}}"
       
        payload.Add(payloadstring)
       
        Lplan.Publish(PublishTopic, payload)
        Lplan.Publish("test" + PublishTopic, payload)
       
        Thread.Sleep(1000000)
       
        LedGreen = Not LedGreen

    End Event

End Class

mc-Abe

  • Full Member
  • ***
  • Posts: 167
    • View Profile
    • mc-Things
Re: Red LED blinks without reference in code
« Reply #6 on: July 11, 2016, 12:26:14 pm »
This dose seem like your device is resetting but I don't see anything in the code that would cause that. Could you try a new battery? It could potentially be that your battery is actually low and the device resets every once in a while.

I am running the example and also added the LED change just to be safe and the out put on my MQTT borker is showing the reports coming in every 10s.

Code: [Select]
1468257840: Received PUBLISH from Gateway (d0, q0, r0, m0, 'losant/577144f8af5318010042c29b/state', ... (72 bytes))
1468257845: Received PINGREQ from Gateway
1468257845: Sending PINGRESP to Gateway
1468257850: Received PUBLISH from Gateway (d0, q0, r0, m0, 'losant/577144f8af5318010042c29b/state', ... (72 bytes))
1468257855: Received PINGREQ from Gateway
1468257855: Sending PINGRESP to Gateway
1468257859: Received PUBLISH from Gateway (d0, q0, r0, m0, 'mcThings/beacon/00010B51/00010005', ... (17 bytes))
1468257860: Received PUBLISH from Gateway (d0, q0, r0, m0, 'losant/577144f8af5318010042c29b/state', ... (72 bytes))
1468257865: Received PINGREQ from Gateway
1468257865: Sending PINGRESP to Gateway
1468257870: Received PUBLISH from Gateway (d0, q0, r0, m0, 'losant/577144f8af5318010042c29b/state', ... (72 bytes))
1468257875: Received PINGREQ from Gateway
1468257875: Sending PINGRESP to Gateway
1468257880: Received PINGREQ from Gateway
1468257880: Sending PINGRESP to Gateway
1468257880: Received PUBLISH from Gateway (d0, q0, r0, m0, 'losant/577144f8af5318010042c29b/state', ... (72 bytes))
1468257885: Received PINGREQ from Gateway
1468257885: Sending PINGRESP to Gateway
1468257890: Received PUBLISH from Gateway (d0, q0, r0, m0, 'losant/577144f8af5318010042c29b/state', ... (72 bytes))
1468257895: Received PINGREQ from Gateway
1468257895: Sending PINGRESP to Gateway
1468257900: Received PUBLISH from Gateway (d0, q0, r0, m0, 'losant/577144f8af5318010042c29b/state', ... (72 bytes))

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: Red LED blinks without reference in code
« Reply #7 on: July 11, 2016, 04:06:41 pm »
Some of my modules started blinking a red led after the latest gateway update. It stopped after I updated the modules to the latest firmware and then reprogrammed the code onto them. They were beaconing prior to that but not sending mqtt messages. I am guessing they were flashing red when they were supposed to send the messages but I never timed them. My code had no instructions for the led. Unfortunately while placing one of my modules back where I had it I slipped and dropped it a meter to the ground and it now seems to be dead :( really hoping the enclosures aren't far away because I think that would have helped.
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894

millennial

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Red LED blinks without reference in code
« Reply #8 on: July 15, 2016, 12:58:26 pm »
The battery is reporting 3033. According to one of the mc-things videos, anything above 2300 means a good battery.

I am wondering if this is a mc-gateway to Losant gateway issue. My next step will be to see if any program can run without the red resets happening.

mc-T2

  • Administrator
  • Sr. Member
  • *****
  • Posts: 252
  • mc-Things! The opportunities are endless!
  • Location: Canada
    • View Profile
Re: Red LED blinks without reference in code
« Reply #9 on: July 15, 2016, 02:40:08 pm »
@millennial/Plains - We are releasing some new firmware and a new version of mc-Studio later today. I believe that the issues you are seeing should be resolved in the update. After release, please be sure to update everything and test out your programs again and let us know how it goes.
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

millennial

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Red LED blinks without reference in code
« Reply #10 on: July 15, 2016, 02:42:52 pm »
Great! Thanks, mc-T2. My device is working now after having come back from Lunch with everything powered off. Magical, but inconsistent.

I figured the mc-things team knew more about these things than we do. I love having all of these updates! Keep it up!

millennial

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Red LED blinks without reference in code
« Reply #11 on: July 16, 2016, 09:56:56 pm »
Bad news. I updated everything and tried my programs again, but I am still seeing my mc-modules reset regularly.

mc-Abe

  • Full Member
  • ***
  • Posts: 167
    • View Profile
    • mc-Things
Re: Red LED blinks without reference in code
« Reply #12 on: July 17, 2016, 12:03:18 am »
Did you also update your mc-Studio? The latest version of the module firmware requires the new mcStudio.

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: Red LED blinks without reference in code
« Reply #13 on: July 17, 2016, 08:42:12 am »
Thanks for the update I will try it out at the earliest opportunity.
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894

millennial

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Red LED blinks without reference in code
« Reply #14 on: July 17, 2016, 12:25:11 pm »
It's a new day, so lets try this again:

1) Downloaded mc-Studio Application V0.7-895, Host Processor BIN File Download: BIN FILE V0.7-405, Application Processor BIN File Download: BIN FILE V0.6-360, and BIN File Download: V0.7-359.
2) Uninstalled mc-Studio via control panel.
3) Installed mc-Studio.
4) Opened OTA Updater, make sure "Ready", load mc-Gateway host .bin, click "Search Device", power on mc-Gateway, once found click "Start Update"
5) Copy mcGw110.bin to a Flash Drive, plug Flash Drive into mc-Gateway and follow firmware update procedure.
6) Load mcMod110-v0.7-359.bin into OTA Updater, click "Search Device", power on mc-Module, once found click "Start Update". Rinse and repeat for 4 total mc-Modules.
6a) While updating the second mc-Module, I noticed that the first mc-Module has already started doing the resets with the blinking red LED. While typing 6a, the second mc-Module that just completed a firmware update also started blinking. Does a firmware update clear any loaded programs?
7) With my 4 devices blinking like a disco scene, I closed OTA Updater and took out all of the batteries from the mc-Modules.
8. Launch mc-Studio, prepare my code and click "Build the Application"
9) Power on mc-Gateway, open Tools -> Devices, connect to Gateway running 6-360 and 7-405, power on a mc-Module, connect to Module with version 7-359 (this took 140 seconds, so I aborted. I clicked "Connect Device" again and was connected in 1 second. Explain?).
10) Prepare code for next mc-Module, Build the Application, power on mc-Module, connect to new mc-Module (though first mc-Module was successfully loaded with code and the programming environment showed the virtual device, the Devices window still showed the first mc-Module was connected in the checkbox. Connecting straight to the new mc-Module worked in 8 seconds, but the application window then showed the old mac address. Connected to virtual device manually, but the new mc-Module then still had a checkbox checked. Just disconnected gateway and reconnected with success. Please try to make the UI accurate.
11) Loaded the second mc-Module. Repeat for last 2 mc-Modules.

I increased the event interval that reads temperature from 10 seconds to 5 minutes. Not sure if it was this total reset process or if there is a memory leak from queuing MQTT so quickly (10 seconds), but I am not seeing the red resets AND I am getting data into my dashboard. Good news, but a slow process connecting to the modules. I need a mc-Dev board  :-\