Wifi Module reboots when setting time

Im having an issue with a roving networks wifi bee module from Tinysine.

The datasheet says:

  1. The command time - sets the rtc clock according to the ntp server specified, Im using the default.

  2. My library's function getRTC - calls the module's show t t\r - which shows the time from the rtc on the wifi module.

But for some reason it reboots when I use those commands and I get a neverending 2 second delay Alarms set in the serial monitor. Here is the sketch:

#include <Wire.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <WiFlyHQ.h>
#include <SoftwareSerial.h>

void terminal();

WiFly wifly;                          //WIFI
String data;                          //WIFI


const byte bufferSize = 32;
char dataBufferToReceive[bufferSize];  //for the time
int dataSize = 256;  //for the size
long int uptime;
char timezone;
long int rtc;
char MyTime[20];

void setup(){
  Serial.begin(9600);  
  Serial.println("Alarms set!");
  delay(2000);
  thisandthat();
}


void thisandthat(){
  // set time from ntp
  //wifly.setTimeAddress("129.6.15.30");//ntp-nist.ldsbc.net"); //28, 29 or 64.113.32.5 or 216.229.0.179
  //wifly.setTimePort(123);
  //wifly.setTimezone(7);
  //wifly.setTimeEnable(5); //maybe because we dont want it to set time on powerup
  //wifly.time(); //this line causes it to reboot?
  //wifly.save();
  delay(1000);                                  

   // there must have been a line with MyTime that I erased
   //uptime = wifly.getUptime();
   //timezone = wifly.getTimezone();
   //rtc = wifly.getRTC();
   
   Serial.print("uptime: ");
   Serial.println(uptime);
   Serial.print("timezone: ");
   Serial.println(timezone);
   Serial.print("rtc: ");
   //Serial.println(rtc);
   Serial.print("MyTime from wifly getTime: ");
   //Serial.println(MyTime);
   Serial.println("Getting time proper... ");

  //Get time from wifi module
  //if (wifly.time()) {                              // My testing of rtc
    //print time
    delay(1000);                                  // My testing of rtc below
    //int something = wifly.getRTC();
    Serial.print("RTC from wifly getRTC: ");
    //Serial.println(something);
    Serial.print("Time of buf: ");
    //Serial.println(wifly.getTime(dataBufferToReceive, sizeof(dataBufferToReceive)));
  //} else {
    Serial.println("Failed to get time");
  //}
}

void loop(){
  //Alarm.delay(10);
}
void MorningAlarm() {
  //Serial.print("Firing Alarm");
 }

/* Connect the WiFly serial to the serial monitor. */
void terminal(){
   while (1) {
  if (wifly.available() > 0) {
      Serial.write(wifly.read());
  }
  if (Serial.available() > 0) {
      wifly.write(Serial.read());
  }
   }
}
  1. My library's function getRTC - calls the module's show t t\r - which shows the time from the rtc on the wifi module.

You did not provide a link to your library.

    //int something = wifly.getRTC();

This suggests to me that you haven't a clue what the getRTC() method returns.

I don't know why you expect us to guess which lines of code are causing the problem. Is it something that is commented out? If not, GET RID OF THAT CRAP.

If it is, why the hell is it commented out?

OK I didn't explain myself clearly.

I have 2 places where I try to get the time:

A. The first few lines where I do wifly.time and wifly.getRTC. These commands are using the library WiflyHQ from harlequin at github.

B. The second group of lines where i use the if code block.

In either case it does the same, keeps looping. I commented pretty much everything because I was trying to find the offending line. As you can see I ended up commenting everything. But then of course that's no good because I can't get the time :slight_smile:

Sorry I didn't explain it clearly.

Here is the link to the library:

In the library, getRTC() is defined as returning a 32 bit type. You are trying to stuff that 32 bit type into a 16 bit variable.

You need to create code that illustrates your problem ONE way. No commented out code. Leave the code in the failing state, since that is obviously the way you want to use it.

There may be issues where the library does not allocate enough space for an array and then writes beyond the end of the array that it allocates.

It is much easier to track that down if you provide a 20 line program than illustrates the problem than it is when you provide a 50 line program with most of the code commented out and say "when I do this the program doesn't crash". When you do that, we have to guess which function call is causing the problem.

Post code with Serial.print() statements, and show the output.

I got it. The problem I believe, was that I wasnt calling the wiflySerial.begin. Since I took the code from a previous working sketch where I was calling the wifly shield code upon request, this was failing.

What was getting printed was simply Alarms set! in which is only called once in the setup. I wonder why that was causing the setup() to be called over and over.

Since you're internet enabled, you can use NPT (time server) to get time. You don't have to deal with daylight savings.

I finally got the time setting working. The time server that came as default is either offline or unreachable. I used a different one
Thanks