Well, I tried it at 0, then at 1, then at 100, and again at 1000, but I still don’t get alarms fired. This is weird. I feel like I’m doing it way wrong, since noone else seems to have the problem. @bko Can I PM you a link to a gist containing my entire sketch?
Hi @damccull
Sure! I can look at it tonight.
Re-reading your code above, you seem to be taking the current time plus 0, 2, 4,…222 seconds and making a repeating alarm for all those times. That seems very fast to me and I am not sure what you are trying to do. I think most folks are using the hour, minute, second interface, not the 32-bit time one you are using.
You know that by default the library allows for dtNBR_ALARMS which is defined to be 6 while you are making 112 alarms. You should look at the return value of the Alarm.alarmRepeat() call, aid in your code above and see if it is dtINVALID_ALARM_ID which is value 255.
@bko I didn’t know it only allowed 6 alarms! How can I increase that number? I hope I don’t have to modify the library as a whole. Thanks for letting me know that 255 is the invalid alarm id value. I couldn’t figure out why all my alarms were getting the same ID Is this library even going to be able to handle 112 alarms if I need it to?
I’m only using the stepped times in the for-loop to test and see if I can get the code working. Eventually, these will be user-configurable.
I did look at the various public methods of the library, and it seems like all the hour, minute, second functions simply translate them into a unix timestamp anyways and then pass it to the method I’m using, so I figured that it would be easier for testing to just use the timestamp as given.
For real time use we can definitely look into STM32’s onchip RTCAlarm interrupts like we currently do for Spark.sleep.
You should probably look at the original author’s site here:
http://www.pjrc.com/teensy/td_libs_TimeAlarms.html
You can increase the number of alarms by changing the line:
#define dtNBR_ALARMS 6 // max is 255
You won’t be able to load the library invisibly on the web IDE then–you will need to grab the files from github and add it as files on tabs using the little circle-plus in the upper part of the web IDE page.
@bko thanks for the link. I downloaded the zip there and found a readme file in it. It says the ram usage will be equal to dtNBR_ALARMS * 11 but it doesn’t give a unit. Do you think this is bytes or kilobytes? To my knowledge, spark only has 20kb of ram (according to kickstarter page). Could this be why I am unable to set the number of alarms I need? I’m still getting 255 as the alarm ID for all my alarms after raising the limit (and copying the library files into my own project).
@damccull, the unit is bytes and the Spark has less than 20Kb of available RAM (more like 8-10KB). I can’t help but wonder why you are setting so many alarms. Can you explain what you are trying to do?
The reason you were not able to set 112 alarms was not RAM. It was dtNBR_ALARMS being set to 6.
@peekay123, I suppose I haven’t really stated my objective, have I? Ok, what I’m doing is building a doorbell controller with user-scheduled “quiet times”. Basically, I want the user to be able to put in various times to turn the doorbell on and off.
0800 - on
1300 - off
1430 - on
2100 - off
I want the user to be able to enter up to 8 changes per day for a 7 day period. This is where I’m getting 112 from.
I can do this already without the TimeAlarm library using just a loop. but the alarms don’t repeat. Since I was using a unix timestamp, they were only one-shot alarms that would never run again after the date and hour the timestamp represented. I don’t know how to make them roll over to the next week on the same day.
I figured I’d give TimeAlarms a shot since it seems to handle repeating alarms natively. I think, though, I may go back to my old approach and modify it slightly if I can’t get this to work.
That's exactly what I did for my doorbell/fingerprint reader.. I wanted to have different users to have different access times
I did an hourly schedule though. I set it up with a usb/serial connection for each user.. When the fingerprint is recognized it checks the time from the cloud and looks at that users schedule and determines whether to let them in or not.
Hi @bko,
I am using this library to test the scheduling. What I am observing is that the core is becoming unresponsive after 2-3 hours (I am using Alarm.delay(3)). If I am using the same call but with interval construct within the loop say for example:
If (elapsedMillis >= 20000) {
Alarm.delay(3);
elapsedMillis = 0;
}
In this scenario also, core becomes unresponsive but after longer period of time, around 10 hours. It seems Alarm.delay is causing some issue.
Anyone faced such problem with the time schedule Library?
If you can share your code, I might be able to help more. I don’t think there is anything in TimeAlarms that consumes memory per call. I have tested it overnight and it worked for me.
That said, Alarm.delay(3) meaning 0.003 seconds of delay is really, really small for a real-time system. Is there a good reason you using such a small time interval?
Yes, there is a local tcp server loop also running and hence I want to keep minimum delay. To achieve this and to keep the delay minimal, I am using the elapsedMillis to control the interval of firing of Alam.delay(3) which is around 20 seconds.
OK so I think it is a lot more likely your TCP server is failing after some amount of time. Do you have some evidence that Alarm.delay() is causing your problems?
When you say unresponsive, what do mean? That the TCP server no longer responds to connections?
Does the main LED flash red or anything like that?
Core continues to be in breathing cyan. It does not respond to cloud or local request. If I comment out the Alarm.delay then I do not encounter this issue.
Let me also check with commenting out local tcp server loop to see if there is any conflict between local tcp server and Alarm.delay.
Is this an older core that could still need deep update? I would do that if it applies (the web IDE will tell you).
Core is updated with the latest patch version (CC3000 – 1.28). Though I am able to figure out that Alarm.delay is not causing this issue but am not sure why the core is becoming unresponsive after 22 hours or so. If I compile my application.cpp with Debug = Y, will that help to determine the issue?
Hi @amit_singh
You can enable debug printing by following what was done in this thread, but I don’t really recommend it.
That is a big hammer for debugging the internals of the Spark code.
You should probably just add your own Serial.print() statements in your code instead.
Another option is to use the Spark.publish() function to send debug messages to the cloud periodically (once per second max rate allowed with a burst of upto 4).
Hi @bko,
This is what I have observed in last couple of days.
The user loop execution is becoming slower and slower with the passage of time and after around 22 hours or so, it really becomes very slow. Debug messages are getting printed after long duration and moreover even output is not proper. I am attaching a sample debug output…
–ConnectionMonitor Initiated–
–Time Alarm Chech Initiated–
–ConnectionMonitor Initiated–
–Ti–ConnectionMonitor Initiated–
–Time–ConnectionMonitor Initiated–
–ConnectionMonitor Initiated–
d–
–Conne–Connect–Time Alarm Chech Initiated–
–ConnectionMonitor Initiated–
–Time Alarm Chech Initiated–
–ConnectionMonitor Initiated–
–ConnectionMonitor Initiated–
–Time Alarm Chech Initiated–
–ConnectiomMonitor Initiated–
–ConnectionMonitor Initiated–
itiated–
–ConnectionMonitor Initiated–
–ConnectionMonitor Initiated–
–ConnectionMonitor Initiated–
–ConnectionMonitor Initiated–
–ConnectionMonitor Initiated–
–Time Alarm Chech Initiated–
–C--ConnectionMonitor Initiated–
After around 22 hours, spark is also losing connetion to cloud. Core is also not able to ping to any IP as well using WiFi.ping(…) within the loop.
OK, so to summarize as I understand it, you have figured out that the slowdown is not caused by Alarm.delay() but you still have your TCP server, right?
Are you using Arduino String class? It allocates memory every time you construct and object and you could be running out of heap. Statically allocated C style char arrays that you manage yourself are better in some situations.
Can you post your code? It certainly sounds like a memory leak type of problem.
Hi @bko,
Code is bit big. Can you provide your Email ID.