<commit_before>/*
  Qmote Humidity and Temperature Logger with Daikin Air Conditioning Automatic Control

  Get the humidity and temperature reading and log them on the cloud storage will never be easier with Qmote Maker's Module
  For more information, please refer to http://qblinks.com/devkit
  For Sensirion SHT3x Arduino library, please refer to https://github.com/winkj/arduino-sht
  For the information of AltSoftSerial, please refer to https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
  For the information of Daikin IR Control, please refer to https://github.com/danny-source/Arduino_IRremote_Daikin
  
  Author: <NAME>, Qblinks Inc.
  Date: Sep 20th, 2015
*/

#include <AltSoftSerial.h>
#include <Wire.h>
#include <elapsedMillis.h>
#include <IRdaikin.h>
#include "sht3x.h"

// Using Sensirion SHT3x for the accurate measurements
SHT3X sht3x;

// for AltSoftSerial, TX/RX pins are hard coded: RX = digital pin 8, TX = digital pin 9 on Arduino Uno
AltSoftSerial portOne;
String recvLine = "";
int resend = 0;

// Daikin Control
IRdaikin irdaikin;
int isOn = 0;

// each power cycle shall not control the air conditioning more than 12 hours
bool stopAirCondRunning = false;

//  ambient environmental parameters
#define TEMP_SETTING          24          // cooling setting to this temperature
#define HEAT_INDEX_HIGH       28          // restart cooling if temperature reaches this measurement
#define HEAT_INDEX_TOO_HIGH   30          // use Heat Index to check if the ambient condition needs to be changed, if so, KEEP_OFF_TIMER will be ignored
#define TEMP_HIGH             26.5        // Highheat index may be caused by Rh, set High limitation to determine cooling or dehumidifier
#define TEMP_LOW              25          // stop cooling or switch to humidifier if temerature reaches this measurement
#define TEMP_TOO_LOW          23.5        // if temperature reaches this value means humidifier goes too much, turn off everything
#define RH_HIGH               69          // restart humidifier if Rh reaches to this measurement
#define RH_LOW                60          // stop humidifier if Rh reaches to this measurement

// avoid frequent ON-OFF mode switch
#define KEEP_ONOFF_TIMER      45
#define RESEND_ATTEMPS        3
#define RESEND_CMD_TIMER      30

#define MODE_OFF              0
#define MODE_COOLING          1
#define MODE_DEHUMIDIFIER     2

// Elapsed Time Control
elapsedMillis timeElapsed;
elapsedMillis resendTimer;
elapsedMillis ignoranceTimer;

/**
 *  Setup
 */
void setup() {
  // Setup SHT3x
  sht3x.setAddress(SHT3X::I2C_ADDRESS_44);
  sht3x.setAccuracy(SHT3X::ACCURACY_MEDIUM);
  Wire.begin();

  // Start the software serial port
  portOne.begin(38400);

  // let serial console settle
  delay(3000);

  // reset the air conditioning control
  isOn = MODE_OFF;
  resendTimer = 0;
  ignoranceTimer = 0;
  stopAirCondRunning = false;

  // needs no UART echo
  String qmoteCmd = "ATE0\r\n";
  portOne.write(qmoteCmd.c_str());
  delay(3000);

  // skip the KEEP_ONOFF_TIMER to initiate the first mode check
  timeElapsed = (long) KEEP_ONOFF_TIMER * (long) 60000;

  // send the first one
  qmoteCmd = "ATBN=0x0A,\"RhT Starts\"\r\n";      // using click combination code 0x0A
  portOne.write(qmoteCmd.c_str());                // output to Maker's module

  // delay extra 10 seconds so the first RhT information can be sent to Qmote
  delay(10000);
}

/**
 *  Flash Qmote LED
 */
void flash_LED()
{
  String qmoteCmd;
  
  // flash Qmote LED as indicator
  delay(2000);
  qmoteCmd = "ATL1=5\r\n";
  portOne.write(qmoteCmd.c_str());

  // off LED
  delay(29000);
  qmoteCmd = "ATL0\r\n";
  portOne.write(qmoteCmd.c_str());  
}

/**
 *  WeMo ON
 */
void wemo_fan_on()
{
  String qmoteCmd;<commit_msg>reduced LED flash time<commit_after>/*
  Qmote Humidity and Temperature Logger with Daikin Air Conditioning Automatic Control

  Get the humidity and temperature reading and log them on the cloud storage will never be easier with Qmote Maker's Module
  For more information, please refer to http://qblinks.com/devkit
  For Sensirion SHT3x Arduino library, please refer to https://github.com/winkj/arduino-sht
  For the information of AltSoftSerial, please refer to https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
  For the information of Daikin IR Control, please refer to https://github.com/danny-source/Arduino_IRremote_Daikin
  
  Author: <NAME>, Qblinks Inc.
  Date: Sep 20th, 2015
*/

#include <AltSoftSerial.h>
#include <Wire.h>
#include <elapsedMillis.h>
#include <IRdaikin.h>
#include "sht3x.h"

// Using Sensirion SHT3x for the accurate measurements
SHT3X sht3x;

// for AltSoftSerial, TX/RX pins are hard coded: RX = digital pin 8, TX = digital pin 9 on Arduino Uno
AltSoftSerial portOne;
String recvLine = "";
int resend = 0;

// Daikin Control
IRdaikin irdaikin;
int isOn = 0;

// each power cycle shall not control the air conditioning more than 12 hours
bool stopAirCondRunning = false;

//  ambient environmental parameters
#define TEMP_SETTING          24          // cooling setting to this temperature
#define HEAT_INDEX_HIGH       28          // restart cooling if temperature reaches this measurement
#define HEAT_INDEX_TOO_HIGH   30          // use Heat Index to check if the ambient condition needs to be changed, if so, KEEP_OFF_TIMER will be ignored
#define TEMP_HIGH             26.5        // Highheat index may be caused by Rh, set High limitation to determine cooling or dehumidifier
#define TEMP_LOW              25          // stop cooling or switch to humidifier if temerature reaches this measurement
#define TEMP_TOO_LOW          23.5        // if temperature reaches this value means humidifier goes too much, turn off everything
#define RH_HIGH               69          // restart humidifier if Rh reaches to this measurement
#define RH_LOW                60          // stop humidifier if Rh reaches to this measurement

// avoid frequent ON-OFF mode switch
#define KEEP_ONOFF_TIMER      45
#define RESEND_ATTEMPS        3
#define RESEND_CMD_TIMER      30

#define MODE_OFF              0
#define MODE_COOLING          1
#define MODE_DEHUMIDIFIER     2

// Elapsed Time Control
elapsedMillis timeElapsed;
elapsedMillis resendTimer;
elapsedMillis ignoranceTimer;

/**
 *  Setup
 */
void setup() {
  // Setup SHT3x
  sht3x.setAddress(SHT3X::I2C_ADDRESS_44);
  sht3x.setAccuracy(SHT3X::ACCURACY_MEDIUM);
  Wire.begin();

  // Start the software serial port
  portOne.begin(38400);

  // let serial console settle
  delay(3000);

  // reset the air conditioning control
  isOn = MODE_OFF;
  resendTimer = 0;
  ignoranceTimer = 0;
  stopAirCondRunning = false;

  // needs no UART echo
  String qmoteCmd = "ATE0\r\n";
  portOne.write(qmoteCmd.c_str());
  delay(3000);

  // skip the KEEP_ONOFF_TIMER to initiate the first mode check
  timeElapsed = (long) KEEP_ONOFF_TIMER * (long) 60000;

  // send the first one
  qmoteCmd = "ATBN=0x0A,\"RhT Starts\"\r\n";      // using click combination code 0x0A
  portOne.write(qmoteCmd.c_str());                // output to Maker's module

  // delay extra 10 seconds so the first RhT information can be sent to Qmote
  delay(10000);
}

/**
 *  Flash Qmote LED
 */
void flash_LED()
{
  String qmoteCmd;
  
  // flash Qmote LED as indicator
  qmoteCmd = "ATL1=5\r\n";
  portOne.write(qmoteCmd.c_str());

  // off LED
  delay(3000);
  qmoteCmd = "ATL0\r\n";
  portOne.write(qmoteCmd.c_str());  
}

/**
 *  WeMo ON
 */
void wemo_fan_on()
{
  String qmoteCmd;
{'fraction_non_alphanumeric': 0.08093645484949832, 'fraction_numerical': 0.024749163879598662, 'mean_word_length': 3.0919540229885056, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '249385', 'n_tokens_mistral': 2581, 'n_tokens_neox': 2413, 'n_words': 809}