2

これは、自動ブラインドを実行するためのコードです。ただし、プログラムが実行されないため、ループ内でメモリリークが発生しているようです。XOBXOB を使用してデータを入力しています。実際に壊れている場所については、以下をご覧ください。

void loop()
{
    Serial.println("loop");
    // New XOB request every 4 seconds (if previous response has been received)
    if (lastResponseReceived && (abs(millis() - lastRequestTime) > 4*1000)) {

       // if the connection has dropped, reconnect
       while (!XOB.connected()) XOB.connect();

       // Reset timer and response flags. Then, request "XOB" contents
       lastResponseReceived = false;
       lastRequestTime = millis();
       Serial.println("requesting xob");
       //enter name of XOB
       XOB.requestXOB("XOB");

       Serial.println("XOB requested!");

     }

     // Load response a character at a time when it is available.
     // If loadStreamedResponse returns true, a completed response has been received
     // Get the "switch" message from the XOB and turn the LED on/off
     // NOTE: The message contents are returned with quotes. So, include them
     // in the comparison statement.
     // Serial.println("LSR: ");
     // Serial.print(XOB.loadStreamedResponse());

これは、ループが実行されない場所です。XOBXOB からのデータのストリームを保存できないようで、loadStreamedResponse は false を返します。

     if (!lastResponseReceived && XOB.loadStreamedResponse()) {
     Serial.println("requesting reponse");
     lastResponseReceived = true;


     Serial.println("Get Xob Messages");
     //Gets the string from value.
     String str_value = XOB.getMessage("value");
     Serial.println(str_value);

     //Gets the string from switch
     String str_switch = XOB.getMessage("switch");
     Serial.println(str_switch);

     String str_text = XOB.getMessage("text");
     Serial.println(str_text);

     //If time is not set, get the time from text xob.
     if(time_set == false) {

         Serial.println("setting time");
         // insert code to parse time and set it from the text xob.

         time_set = true; 
     }  


     // parse the hour from value and convert to minute for wake hour
     String string_hour = str_value.substring(1,3);
     int wake_hour = string_hour.toInt();
     //Serial.println(wake_hour);

     // parse minute from value and convert to int for wake minute
     String string_minute = str_value.substring(3,5);
     int wake_minute = string_minute.toInt();
     // Serial.println(wake_minute);

     // compare wake_minute and wake_hour with current time
     // convert both to minutes for comparison

     int wake_time = wake_minute + (60 * wake_hour);

     int current_time = 738;  //minute() + (hour() * 60);

     Serial.println("checking wake condtions");
     // rise up blinds slowly if the wake time is + or - 1 minute and if the blinds are        closed.
     if((wake_time == current_time || wake_time == (current_time - 1) || wake_time == (current_time + 1))
      && blinds_open == false ) {
          Serial.println("Natural Wakeup");
          rollup_blinds_slow();
          blinds_open = true; // blinds should be open now.
      }



     // Check for opening up blinds condition. Blinds must be closed, to open them
     Serial.println("Checking Open Condition");
     if (str_switch.equalsIgnoreCase("\"ON\"") && blinds_open == false) {
         Serial.println("Blinds Up");
         rollup_blinds_fast();
         blinds_open = true;
         Serial.println(blinds_open);
     }


     Serial.println("Check closing condition");
     // Check for closing blinds condition. Blinds must be closed, to open them
     if (str_switch.equalsIgnoreCase("\"OFF\"") && blinds_open == true) {
         Serial.println("Blinds down");
         rolldown_blinds_fast();
         blinds_open = false;
     }
}
4

0 に答える 0