Author Topic: Current time in HH:MM:SS  (Read 2302 times)

michal

  • Newbie
  • *
  • Posts: 43
    • View Profile
Current time in HH:MM:SS
« on: July 24, 2016, 12:46:45 am »
How would I go about creating a timestamp with the format HH:MM:SS??

I've been trying all sorts of things based on google searches for VB.NET code but nothing seems to be valid according to mcStudio.

Share on Facebook Share on Twitter


michal

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Current time in HH:MM:SS
« Reply #1 on: July 24, 2016, 02:08:40 am »
I tried this:

Code: [Select]
Class Test
    Shared Event generateTimestamp() RaiseEvent Every 1 Minutes
        Dim dat As DateTime = DateTime.Now()
        Dim payload As ListOfByte = New ListOfByte
        Dim timestamp As String = dat.ToString("HH':'mm':'ss")
       
        payload.Add(timestamp)
        Lplan.Publish("mcThings/Test", payload)
    End Event
End Class

But I feel I may have bricked multiple modules with it as I can no longer connect to them after uploading this code :( Is there a way to clear the program without connecting to the module via the gateway?

michal

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Current time in HH:MM:SS
« Reply #2 on: July 24, 2016, 02:50:22 am »
In fact the modules with this code on them no longer even send out beacons :(

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: Current time in HH:MM:SS
« Reply #3 on: July 24, 2016, 09:47:39 am »
Do you always push the code to the device without testing the code in debug mode?
I would recommend to debug (you do not need to set breakpoints) all code first just to verify it, and if the code "brick" the device, just reboot it and it's back to normal.

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: Current time in HH:MM:SS
« Reply #4 on: July 24, 2016, 06:45:27 pm »
As he was saying. Code saved to the modules in debug mode will not be permanently saved to the module. Once you power cycle the module it will lose that code.
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894

helge

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Current time in HH:MM:SS
« Reply #5 on: July 25, 2016, 04:30:29 am »
Quote
Do you always push the code to the device without testing the code in debug mode?
I would recommend to debug (you do not need to set breakpoints) all code first just to verify it, and if the code "brick" the device, just reboot it and it's back to normal.

I have to agree, but nevertheless a bug executed within a vm – according to the architeture chapter 3 of the mc-Script manual – shouldn't brick the whole module. Period.

plains203

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: Current time in HH:MM:SS
« Reply #6 on: July 25, 2016, 06:20:45 am »
I thought I bricked a module once and found that after I pulled the battery and left it out for a while 1 minute or so then put it back in I was able to connect to it with the updater. Once I flashed it again I was able to access it with the McStudio. I had to do the power off method again to get it to connect.
McGateway 0.6-360, 0.7-405
McModules 0.7-358
McStudio 0.7-894

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Current time in HH:MM:SS
« Reply #7 on: July 25, 2016, 10:33:06 am »
We did a lot of work to prevent bricking the device. The only case we know where it goes wrong, which is solved in the latest version, is the repeated reset case. If the device resets before you can make a connection it is bricked.
Why do we reset the device? The most common case is that the application program request services from the OS and the OS can't keep up and runs out of memory. In that case we have to reset the device because we cannot continue.

We have fixed this by keeping track of the up-time. If the device need to reset and it is not up for more than 2 minutes we remove the script and wait for a connection with mc-Studio.

So what if your device is bricked and you don't have the latest code? Well that is simple. After a reset the device is looking for 5 seconds to find a boot-loader (mc-Dongle) before starting the OS and running the script. This makes it possible to load the latest software.


helge

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Current time in HH:MM:SS
« Reply #8 on: July 25, 2016, 11:55:11 am »
Quote
The only case we know where it goes wrong, which is solved in the latest version

Well, not really. I have a mc-Module here which will be recognized by the OTA-Updater, and can flash the firmware, but it doesn't send a beacon and is not recognized in mc-Studio. The device locked up during an i2c operation in the boot event. mc-Abe got the source and is currently investigating this issue. But please give us the possibility to reset the modules to factory defaults, I even have access to a programmer for the nrf51 which can handle a complete wipe of the chip ... just release the hex files to get it working again, pretty please. I'd sign an NDA if thats necessary to get those.

mc-Abe

  • Full Member
  • ***
  • Posts: 167
    • View Profile
    • mc-Things
Re: Current time in HH:MM:SS
« Reply #9 on: July 26, 2016, 05:28:37 pm »
@michal

Seems like the .ToString documentation is missing the format information. We will be adding that but for now, DateTime is in ISO8601 format which by default has a string representation that looks like this: YYYY-MM-DDTHH:MM:SS+hh:mm. You can use .ToString("L") for local time to get the time in your local time with no timezone information or use .ToString("Z") to get Zulu (UTC) time.

The other option is to use the documented functions of the DateTime object to extract the hour, minute, and second information and manually form a timestamp in your desired format.

It is probably worth mentioning that mc-Script is a VB.NET like language in its syntax. We do not support all the functionality of the .NET framework.

Also if you update to the latest mc-Gateway Host Processor firmware, you should be able to connect to your module and reprogram it. It is not bricked. It has entered debug mode since your code did not successfully create a string (since "HH':'mm':'ss" is not a valid format string) and tried to add it to a ListOfByte. This would have caused a run-time error which you did not see since you didn't debug the code. Beacons are not sent when device enters debug mode.

michal

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Current time in HH:MM:SS
« Reply #10 on: July 29, 2016, 02:57:17 am »
Yikes!

I thought people had stopped replying but it seems my notification was disabled :P

So in response:

1. I've only ever used Debug and not Release (if this is what we are talking about).
2. I didn't realise that Debug code gets reset after you remove the battery.
3. My modules are not behaving as if #2 was true.

While I can rewrite the firmware on the modules or leave them with no battery for days they still do not behave as before once I put the battery back in as I have been unable to connect to them since I first started this thread.

I still have 1 module working (and one as yet unused). With the suggestions here my code on it as as follows (and seems to be working well):

Code: [Select]
Class DownstairsTemp
    Shared Event CheckTemp() RaiseEvent Every 5 Minutes
        Dim Timestamp As DateTime = DateTime.Now()
        Dim Temp As Float = TempSensor.GetTemp()
        Dim Payload As ListOfByte = New ListOfByte
        Dim TempString As String = Timestamp.ToString("Z") + "," + Temp.ToString()
        Payload.Add(TempString)
        Lplan.Publish("mcThings/DownstairsTemp", Payload)
    End Event
    Shared Event CheckBatt() RaiseEvent Every 1 Hours
        Dim Timestamp As DateTime = DateTime.Now()
        Dim Volt As Short = Device.BatteryVoltage()
        Dim Payload As ListOfByte = New ListOfByte
        Dim TempString As String = Timestamp.ToString("Z") + "," + Volt.ToString()
        Payload.Add(TempString)
        Lplan.Publish("mcThings/DownstairsBatt", Payload)
    End Event
End Class

I wanted to use module generated timestamps as if I generate them upon receipt sometimes they come in bulk and the timestamps become meaningless.

I've attached a pic of what the device and beacon windows look like. I can try connecting for thousands of second with nothing. The only one I can connect to is the 6A module.

mc-Abe

  • Full Member
  • ***
  • Posts: 167
    • View Profile
    • mc-Things
Re: Current time in HH:MM:SS
« Reply #11 on: July 29, 2016, 10:11:39 am »
I am not talking about the Debug vs Release. I am talking about the Run (Play Symbol) or the Load button which is next to the Debug vs Release drop down.

If you use the Run button, the code doesn't get permanently loaded into the device and you can debug with breakpoints.
If you use the Load button, the code is loaded into the internal device flash and is not erased on reset.

Have you tried the latest mc-Gateway Host Processor release that came out a few days ago? This version resolved the batch arrival of messages and also improved connection stability. Please try that to see if you can connect to your devices.

michal

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Current time in HH:MM:SS
« Reply #12 on: July 30, 2016, 08:01:09 am »
Thank you.

You're totally right. The new host processor update fixed the problem. I can now connect to and upload new code.

I didn't realise that you could run the code rather than load it in the manner described. I watched the example videos and none of those mentioned that. Very useful to know.

Just trying to get my head around what I can do with the modules and Node-RED and trying to develop a better understanding of how to create more complex flows.

P.S. The new naming convention for the firmware downloads has been very helpful.

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: Current time in HH:MM:SS
« Reply #13 on: July 30, 2016, 08:17:59 am »
I think you should take a better look on the videos then  :)

In the video mcStudio introduction this is all explained in there.

michal

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Current time in HH:MM:SS
« Reply #14 on: July 30, 2016, 08:19:12 am »
Oops. Spoke to soon.

Seems like about 5 hours ago the 2 modules that were working fine stopped logging their MQTT data. One is still beaconing but the other is not.

Incidentally the ones without Type and Version are the ones that used to be working. Not sure if this coincided with the host processor update or not :/