mc-Things

mc-Products => mc-Studio => Topic started by: michal on July 24, 2016, 12:46:45 am

Title: Current time in HH:MM:SS
Post by: michal 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.
Title: Re: Current time in HH:MM:SS
Post by: michal 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?
Title: Re: Current time in HH:MM:SS
Post by: michal on July 24, 2016, 02:50:22 am
In fact the modules with this code on them no longer even send out beacons :(
Title: Re: Current time in HH:MM:SS
Post by: kristofferis 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.
Title: Re: Current time in HH:MM:SS
Post by: plains203 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.
Title: Re: Current time in HH:MM:SS
Post by: helge 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.
Title: Re: Current time in HH:MM:SS
Post by: plains203 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.
Title: Re: Current time in HH:MM:SS
Post by: mc-John 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.

Title: Re: Current time in HH:MM:SS
Post by: helge 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.
Title: Re: Current time in HH:MM:SS
Post by: mc-Abe 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.
Title: Re: Current time in HH:MM:SS
Post by: michal 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.
Title: Re: Current time in HH:MM:SS
Post by: mc-Abe 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.
Title: Re: Current time in HH:MM:SS
Post by: michal 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.
Title: Re: Current time in HH:MM:SS
Post by: kristofferis 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.
Title: Re: Current time in HH:MM:SS
Post by: michal 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 :/
Title: Re: Current time in HH:MM:SS
Post by: michal on July 30, 2016, 08:20:24 am
Indeed kristofferis.

I don't think I've seen that one. Just some of the examples.
Title: Re: Current time in HH:MM:SS
Post by: michal on July 30, 2016, 04:25:01 pm
The two modules that weren't beaconing started to do so overnight. But still no data :/

Title: Re: Current time in HH:MM:SS
Post by: kristofferis on July 30, 2016, 04:28:56 pm
Connect to the device from mcStudio and debug (play button) your code and see if the code works.
If it works and that you are happy with the result, upload the code to the mcModule.
If it then stops working then we have an issue. But please try the above suggestion.
Title: Re: Current time in HH:MM:SS
Post by: michal on July 30, 2016, 05:05:57 pm
The thing is the code has been running without fault continuously for 3 days. It's the same code I pasted earlier.
Title: Re: Current time in HH:MM:SS
Post by: michal on July 30, 2016, 05:58:22 pm
And for what it's worth.. Here are the files that the data gets logged to:

Code: [Select]
pi@raspberrypi:~/public_html $ ls -l *.csv
-rw-r--r-- 1 pi pi   234 Jul 31 08:52 ComputerRoomBatt.csv
-rw-r--r-- 1 pi pi  3675 Jul 31 08:52 ComputerRoomTemp.csv
-rw-r--r-- 1 pi pi  1131 Jul 30 18:26 DownstairsBatt.csv
-rw-r--r-- 1 pi pi 16912 Jul 30 18:37 DownstairsTemp.csv
-rw-r--r-- 1 pi pi   533 Jul 30 18:34 FridgeBatt.csv
-rw-r--r-- 1 pi pi  7127 Jul 30 18:34 FridgeTemp.csv
-rw-r--r-- 1 pi pi   364 Jul 31 08:48 UpstairsBatt.csv
-rw-r--r-- 1 pi pi  5225 Jul 31 08:53 UpstairsTemp.csv

Going to try power cycling the Fridge and Downstairs modules which HAD been working until things went topsy-turvy and which modules work and don't work inverted (only host processor update).

All of them are running the same code except for the publish names.
Title: Re: Current time in HH:MM:SS
Post by: michal on July 31, 2016, 01:34:39 am
Power cycling them did not help. They still beacon regularly but no data.

Occam's Razor would seem to suggest that the host processor firmware is the reason that the originally working modules have stopped working. It might be that the module must be programmed through a gateway that has the current (and not the previous) firmware for them to work (as is the case with the working modules).

So that is what I am going to try next.
Title: Re: Current time in HH:MM:SS
Post by: kristofferis on July 31, 2016, 02:16:48 am
Yes, that's why I asked you to connect to the mcModule and run the code.
Make sure you have latest firmware and software and upload the code again.
And I recommend to always debug the code to verify it.
Title: Re: Current time in HH:MM:SS
Post by: michal on July 31, 2016, 02:27:44 am
Bizarrely, while I was trying to do just that (couldn't connect to the modules to re-upload the code) they both just started working again.

Got about 30 minutes (ie 6 messages every 5 minutes) of data all with an incorrect timestamp (as if the module had been reset, though I hadn't reset it).

Is there some sort of watchdog that resets the modules after about 24 hours?

I will definitely be running rather than loading any unverified code onto my modules in future.
Title: Re: Current time in HH:MM:SS
Post by: michal on July 31, 2016, 03:55:04 am
And now they've all stopped working... And then came back 15 minutes later.. At least the beacons.

There's something going on here as the two that went AWOL yesterday did so at 18:37 and then they all went AWOL for 15 minutes today at 18:38.. It  COULD be a coincidence.. But if it happens again tomorrow around the same time..

We'll see.

EDIT: Oh, and the time reset on one of the modules.
Title: Re: Current time in HH:MM:SS
Post by: michal on August 01, 2016, 07:25:49 am
Umm..

I've come across another problem..

It's the 32nd of July..

Code: [Select]
2016-07-31T23:58:06Z,21.250000
2016-07-32T00:03:06Z,21.375000

I think this may be a bug?
Title: Re: Current time in HH:MM:SS
Post by: kristofferis on August 01, 2016, 08:06:09 am
I agree :) let's add this to the list of bug's.
Title: Re: Current time in HH:MM:SS
Post by: mc-Abe on August 02, 2016, 11:00:40 am
Oops! That is certainly a bug, we have found the issue and it has been fixed. Will be in the next release of mcModule.

There is indeed a watchdog on the module but it is not intended to be triggered. It would be consistent with the 15 minute reset you are seeing though. This is not something that you should see and it intended as a device recovery mechanism. Is it possible for you to share you code? You can private message it to me and I can see why this could be happening.
Title: Re: Current time in HH:MM:SS
Post by: michal on August 05, 2016, 06:43:16 am
Sorry! Didn't notice your post till just now.

The code is the same as I posted earlier. Haven't seen any resets in a couple of days so seems good for now.

Might try logging the UID and uptime as well for debug and tracking purposes.
Title: Re: Current time in HH:MM:SS
Post by: Riverrider on August 05, 2016, 02:48:51 pm
I've been working on an app to turn on a sprinkler timer for 1 hour per day (and, eventually, on selected days) but couldn't get it to activate at the specified hour. Initially tested in the debugger to avoid any "bricking" as mentioned here but without breakpoints. Finally got smart and actually looked at the time being received from DateTime.Now. Also included the string value in an IFTTT log. Here's an excerpt while cycling once a minute:

August 5, 2016 at 02:19PM   Module469   ValveOpen   2016-08-05T23:19:46+05:00   
August 5, 2016 at 02:20PM   Module469   ValveClosed   2016-08-05T23:20:47+05:00   
August 5, 2016 at 03:19PM   Module469   ValveClosed   2016-08-05T19:16:39Z   
August 5, 2016 at 03:20PM   Module469   ValveOpen   2016-08-05T19:17:39Z   

Note that I'm in the US East coast time zone. (The last two entries had the "Z" argument on the ToString() while the missing times where taken up with other things including trying to post log entries with the "L" argument - which refused to post but showed ok in the debugger. What's up with that?)  As you can see, the time zone correction shows a +5 hours where it should be MINUS 5. Is there something I'm missing?
Title: Re: Current time in HH:MM:SS
Post by: Riverrider on August 05, 2016, 04:47:26 pm
I was missing something. It's been months since I first configured the gateway. And yes, it did have +05:00 in the Time Zone field. One must also remember to reset the gateway after changing anything. Still can't get the IFTTT log entries when formatting the time string with the "L" argument. Just doesn't log at all. The other formats work properly.
Title: Re: Current time in HH:MM:SS
Post by: mc-Abe on August 12, 2016, 11:51:32 am
Sorry it took me a while to get back to you on this but I have tracked this down to a bug in conversion to string using the "L" format specifier. You don't see this when you look at the string in the debug window in mcStudio. I have fixed this and will be in the next release of the module.
Title: Re: Current time in HH:MM:SS
Post by: mc-T2 on August 12, 2016, 05:34:47 pm
@Riverrider - We just uploaded new firmware for the mc-Modules and also a new host processor for the mc-Gateway. Please be sure to update your modules and your gateway to fix the time issue.
Thanks!!