{"id":2963,"date":"2017-12-13T22:02:53","date_gmt":"2017-12-13T22:02:53","guid":{"rendered":"http:\/\/grodansparadis.com\/wordpress\/?p=2963"},"modified":"2018-11-04T22:13:56","modified_gmt":"2018-11-04T22:13:56","slug":"vscp-howto-dm-using-timers","status":"publish","type":"post","link":"https:\/\/grodansparadis.com\/wordpress\/?p=2963","title":{"rendered":"#VSCP HOWTO: DM Using timers"},"content":{"rendered":"<p><a href=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2646\" data-permalink=\"https:\/\/grodansparadis.com\/wordpress\/?attachment_id=2646\" data-orig-file=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg?fit=1123%2C794&amp;ssl=1\" data-orig-size=\"1123,794\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"vscp_logo_text_box\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg?fit=580%2C410&amp;ssl=1\" class=\"alignnone size-full wp-image-2646\" src=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg?resize=580%2C410\" alt=\"\" width=\"580\" height=\"410\" srcset=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg?w=1123&amp;ssl=1 1123w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg?resize=300%2C212&amp;ssl=1 300w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg?resize=768%2C543&amp;ssl=1 768w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2017\/08\/vscp_logo_text_box.jpg?resize=1024%2C724&amp;ssl=1 1024w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><\/p>\n<p>Timers. One can wonder what they do in the decision matrix? They even have their own events defined in the <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class2.vscpd\">CLASS2.VSCP<\/a> class.<\/p>\n<p>First let us define what a VSCP timer is.<\/p>\n<p>A VSCP timer is a free running 32-bit timer with millisecond resolution.\u00a0 That is they can hold\u00a0 0xffffffff =\u00a04294967295 milliseconds which mens they will roll over in about 50 days.<\/p>\n<p>There are actions defined to<\/p>\n<ul>\n<li><a href=\"https:\/\/grodansparadis.gitbooks.io\/the-vscp-daemon\/decision_matrix.html#start-a-timer\">Start a timer (0x60)<\/a><\/li>\n<li><a href=\"https:\/\/grodansparadis.gitbooks.io\/the-vscp-daemon\/decision_matrix.html#pause-a-timer\">Pause a timer (0x61)<\/a><\/li>\n<li><a href=\"https:\/\/grodansparadis.gitbooks.io\/the-vscp-daemon\/decision_matrix.html#stop-a-timer\">Stop a timer (0x62)<\/a><\/li>\n<li><a href=\"https:\/\/grodansparadis.gitbooks.io\/the-vscp-daemon\/decision_matrix.html#resume-a-timer\">Resume a timer (0x63)<\/a><\/li>\n<\/ul>\n<p>There is the following\u00a0 internal events defined related to timers<\/p>\n<ul>\n<li><a href=\"https:\/\/grodansparadis.gitbooks.io\/the-vscp-specification\/class2.vscpd.html#type25\">CLASS2.VSCPD, Type = 25 (0x0019) Timer started<\/a><\/li>\n<li><a href=\"https:\/\/grodansparadis.gitbooks.io\/the-vscp-specification\/class2.vscpd.html#type26\">CLASS2.VSCPD, Type = 26 (0x001A) Timer paused<\/a><\/li>\n<li><a href=\"https:\/\/grodansparadis.gitbooks.io\/the-vscp-specification\/class2.vscpd.html#type27\">CLASS2.VSCPD, Type = 27 (0x001B) Timer resumed<\/a><\/li>\n<li><a href=\"https:\/\/grodansparadis.gitbooks.io\/the-vscp-specification\/class2.vscpd.html#type28\">CLASS2.VSCPD, Type = 28 (0x001C) Timer stopped<\/a><\/li>\n<li><a href=\"https:\/\/grodansparadis.gitbooks.io\/the-vscp-specification\/class2.vscpd.html#type29\">CLASS2.VSCPD, Type = 29 (0x001D) Timer Elapsed<\/a><\/li>\n<\/ul>\n<p>To create and start a timer<\/p>\n<pre>&lt;row enable=\"true\" groupid=\"timers\" &gt;\r\n\r\n  &lt;comment&gt;\r\n    Create timer\r\n  &lt;\/comment&gt;\r\n\r\n  &lt;mask priority=\"0\"\r\n        class=\"0xFFFF\"\r\n        type=\"0xFFFF\"\r\n GUID=\"00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00\" \/&gt;\r\n\r\n  &lt;filter priority=\"0\"\r\n          class=\"65535\"\r\n          type=\"23\"\r\n GUID=\"00:01:02:03:04:05:06:07:08:09:0A:0B:0C:0D:0E:0F\" \/&gt;\r\n\r\n  &lt;action&gt;0x60&lt;\/action&gt;\r\n  &lt;param&gt;\r\n    1;10;timer1flag;true\r\n  &lt;\/param&gt;\r\n\r\n&lt;\/row&gt;<\/pre>\n<p>Here a timer with id = 1 is created. The timer has an initial time set to 10 seconds. When this timer elapses it will set the variable \/\/timer1flag\/\/ to true. The last argument is the reload flag. Here it is set to true so when the time has elapsed the initial value will be loaded again and the timer will start again.<\/p>\n<p>In the example above we could have added &#8220;;4&#8221; at the end of the parameter which would have the effect that the reload would stop after four runs. Default is thus forever.<\/p>\n<p>When the timer is started a\u00a0<a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class2.vscpd#type_25_0x0019_timer_started\"><strong>CLASS2.VSCPD, Type = 25 (0x0019) Timer started<\/strong><\/a> event is generated. When the ten seconds has gone and the timer elapses the\u00a0 <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class2.vscpd#type_29_0x001d_timer_elapsed\"><strong>CLASS2.VSCPD, Type = 29 (0x001D) Timer Elapsed<\/strong><\/a> event is generated.<\/p>\n<p>We can use either one of these two generated events to do any action periodically like this.<\/p>\n<pre>&lt;row enable=\"true\" groupid=\"timers\" &gt;\r\n\r\n  &lt;comment&gt; \r\n    Handle timer elapsed\r\n  &lt;\/comment&gt;\r\n\r\n  &lt;mask priority=\"0\"\r\n        class=\"0xFFFF\"\r\n        type=\"0xFFFF\"\r\n GUID=\"00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00\" \/&gt;\r\n\r\n  &lt;filter priority=\"0\"\r\n          class=\"65535\"\r\n          type=\"29\"\r\n GUID=\"00:01:02:03:04:05:06:07:08:09:0A:0B:0C:0D:0E:0F\" \/&gt;\r\n\r\n  &lt;action&gt;0x70&lt;\/action&gt;\r\n  &lt;param&gt;\r\n    \/srv\/vscp\/timefile;1;%isoboth: Timer with  id=%event.data.int32[0] elapsed %lf\r\n  &lt;\/param&gt;\r\n\r\n&lt;\/row&gt;\r\n\r\n\r\n&lt;row enable=\"true\" groupid=\"timers\" &gt; \r\n\r\n   &lt;comment&gt; Handle timer elapsed &lt;\/comment&gt; \r\n   &lt;mask priority=\"0\" \r\n         class=\"0xFFFF\" \r\n         type=\"0xFFFF\" GUID=\"00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00\" \/&gt; \r\n    &lt;filter priority=\"0\" \r\n            class=\"65535\" \r\n            type=\"25\" GUID=\"00:01:02:03:04:05:06:07:08:09:0A:0B:0C:0D:0E:0F\" \/&gt; \r\n\r\n    &lt;action&gt;0x70&lt;\/action&gt; \r\n    &lt;param&gt; \r\n      \/srv\/vscp\/timefile;1;%isoboth: Timer with id=%event.data.int32[0] elapsed counter=%event.data.uint32[0]ms %lf &lt;\/param&gt; &lt;\/row&gt;<\/pre>\n<p>Here some info is just written to a file when the timer is started and when it elapses.\u00a0 \u00a0But if you want to send an event periodically instead or do other actions this is the way to do it.<\/p>\n<p>You don&#8217;t have to give a variable nor a reload flag when you start a timer. If no variable is given (use ;;) it is just ignored. The reload value will be set to false as default\u00a0 value, that is the timer will run only once. As the last parameter you can set the number of times the timer should reload before it should stop.\u00a0 The full documentation is <a href=\"http:\/\/www.vscp.org\/docs\/vscpd\/doku.php?id=vscp_daemon_decision_matrix#start_a_timer\">here<\/a> and <a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class2.vscpd#type_25_0x0019_timer_started\">here<\/a>.<\/p>\n<p>One useful use of timers is to handle resend of events. The working is like this<\/p>\n<p>Send the event you expect a reply event from another node.<\/p>\n<ol>\n<li>Create\/start a timer that have\u00a0 period equal to resend intervals for the event you want to send. The timer should\u00a0 have true for autoloading and the number of autoloads set to the number of resend that are allowed.\u00a0 You can trigger the creation of the timer\u00a0 by make a DM entry that triggering on one of the reserved events for example,\u00a0\u00a0<a class=\"wikilink1\" title=\"class1.local\" href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class1.local\">CLASS1.LOCAL\u00a0<\/a> or <a class=\"wikilink1\" title=\"class1.laboratory\" href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class1.laboratory\">CLASS1.LABORATORY<\/a> so that when you send this local event\u00a0 the actual event will be sent (see next point)<\/li>\n<li>In the timer started event send\u00a0 the event you want to send.<\/li>\n<li>When\/If the expected reply\u00a0 is received pause the timer.<\/li>\n<li>Now if the timer the timer stopped event is detected the reply wait timeout has expired so do timeout handling there by sending another local event or\u00a0<a href=\"http:\/\/www.vscp.org\/docs\/vscpspec\/doku.php?id=class1.error#type_32_0x20_timeout_error\">CLASS1.ERROR, Type = 32 Time out<\/a>.<\/li>\n<\/ol>\n<p>Can be used for much more of course. Just useful and simple.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Timers. One can wonder what they do in the decision matrix? They even have their own events defined in the CLASS2.VSCP class. First let us define what a VSCP timer is. A VSCP timer is a free running 32-bit timer with millisecond resolution.\u00a0 That is they can hold\u00a0 0xffffffff =\u00a04294967295 milliseconds which mens they will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[12,53,13],"tags":[],"class_list":["post-2963","post","type-post","status-publish","format-standard","hentry","category-general","category-howtos","category-vscp"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4raCZ-LN","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2963"}],"version-history":[{"count":5,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2963\/revisions"}],"predecessor-version":[{"id":3830,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2963\/revisions\/3830"}],"wp:attachment":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}