<commit_before>#include "string.h"
#include "LowPower.h"

#define TRUE  1
#define FALSE 0

#define STATUS_FAILED     0
#define STATUS_OK         1
#define STATUS_DATA_RECVD 2

#define DEF_NOTIF_INTERVAL    20000
#define MAX_NOTIF_ACTIVE_TIME 360000
#define CATCH_QUERY_DURATION  2000

#define MATCHED 0

#define DEPLOY_STATUS_PIN 2
#define PH_SENSOR_PIN     A1
#define BATT_LEVEL_PIN    A2

typedef enum {
  UNKNOWN, INACTIVE, IDLE, BUSY
} eState_t;

char  _aRecvBuf[20] = {};
int   _iRecvIdx = 0;
int   _bLiveNotif = FALSE;
int   _bFirstActivate = TRUE;
long  _lLastNotif = 0;
long  _lNotifStartTime = 0;


long  _lStartTime = 0;
eState_t _eState = UNKNOWN;

int utl_match(const char* s1, const char* s2, int iLen);
int dat_procRequest(char* aMsg, int iLen);
int com_recv(char* aBuf);

void setup() {

  /*
   * +++ //no line ending
   * AT+USBDEBUG=OFF //both nl cr
   * AT+BLUNODEBUG=OFF
   * AT+NAME=[]
   * AT+EXIT
   * +++
   */
  Serial.begin(115200);

  pinMode(DEPLOY_STATUS_PIN, OUTPUT);
  digitalWrite(DEPLOY_STATUS_PIN, LOW);

  pinMode(13, OUTPUT);

  _lStartTime = millis();
  sys_setState(INACTIVE);
  //sys_setState(IDLE);
  return;
}

void loop() {
  if (_bFirstActivate) {
    digitalWrite(DEPLOY_STATUS_PIN, HIGH);
    delay(50);
    digitalWrite(DEPLOY_STATUS_PIN, LOW);
    delay(50);
    digitalWrite(DEPLOY_STATUS_PIN, HIGH);
    delay(50);
    digitalWrite(DEPLOY_STATUS_PIN, LOW);
    _bFirstActivate = FALSE;
  }
  
  _iRecvIdx = 0;
  memset(_aRecvBuf, 0, sizeof(_aRecvBuf));

  int iRetVal = com_recv(_aRecvBuf);
  if (iRetVal == STATUS_FAILED) {
    delay(90);
    return;
  }

  if (iRetVal == STATUS_DATA_RECVD) {
    if (dat_procRequest(_aRecvBuf, _iRecvIdx) <= STATUS_FAILED) {
      // Failed
      return;
    }
  }

  if (_bLiveNotif) {
    if (dat_liveNotif() <= STATUS_FAILED) {
      // FAILED
      return;
    }
  }

  delay(90);
  if((_lStartTime + CATCH_QUERY_DURATION) < millis()){ 
    digitalWrite(DEPLOY_STATUS_PIN, HIGH);
    delay(500);
    digitalWrite(DEPLOY_STATUS_PIN, LOW);
    _bFirstActivate = TRUE;
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
    _lStartTime = millis();
  }
  return;
}

int com_recv(char* aBuf) {
  if (Serial.available() > 0) {
    _lStartTime = millis();
    char c = 1;
    while (c >= 0) {
      c = Serial.read();
      if ((c <= ' ') && (_iRecvIdx == 0)) {
        delay(50);
        continue;
      }
      _aRecvBuf[_iRecvIdx++] = c;
      delay(50);
    }
    return STATUS_DATA_RECVD;
  }

  return STATUS_OK;
}

int dat_respSensor() {
  char aBaseStr[64];
  char aValStrPH[10];
  char aValStrBatt[10];
  
  memset(aBaseStr, 0, sizeof(aBaseStr));
  memset(aValStrPH, 0, sizeof(aValStrPH));
  memset(aValStrBatt, 0, sizeof(aValStrBatt));

// float dVal = 14.0 * (random(20, 80) / 100.0);

  // PH data
  int iAdcValPH = analogRead(PH_SENSOR_PIN);
  float dVoltagePH = (iAdcValPH * 5.0) / 1024;
  float dValPH = dVoltagePH;
// float dValPH = dVoltagePH * 2.2570 + 2.6675;

  // Battery data
  int dMaxBatt = 3.7;
  int iAdcValBatt = analogRead(BATT_LEVEL_PIN);
  float dValBatt = (iAdcValBatt * dMaxBatt / 2) / 1024;

  dtostrf(dValPH, 6, 2, aValStrPH);
  dtostrf(dValBatt, 6, 2, aValStrBatt);
  
  strcpy(aBaseStr, " RDATA: pH=");
  strcat(aBaseStr, aValStrPH);
  strcat(aBaseStr, ";");
  Serial.println(aBaseStr);
  
  strcpy(aBaseStr, " RDATA: bt=");
  strcat(aBaseStr, aValStrBatt);
  strcat(aBaseStr, ";");
  Serial.println(aBaseStr);
 
}<commit_msg>[Minor] Updated bluno code to send raw analog vals<commit_after>#include "string.h"
#include "LowPower.h"

#define TRUE  1
#define FALSE 0

#define STATUS_FAILED     0
#define STATUS_OK         1
#define STATUS_DATA_RECVD 2

#define DEF_NOTIF_INTERVAL    20000
#define MAX_NOTIF_ACTIVE_TIME 360000
#define CATCH_QUERY_DURATION  2000

#define MATCHED 0

#define DEPLOY_STATUS_PIN 2
#define PH_SENSOR_PIN     A1
#define BATT_LEVEL_PIN    A2

typedef enum {
  UNKNOWN, INACTIVE, IDLE, BUSY
} eState_t;

char  _aRecvBuf[20] = {};
int   _iRecvIdx = 0;
int   _bLiveNotif = FALSE;
int   _bFirstActivate = TRUE;
long  _lLastNotif = 0;
long  _lNotifStartTime = 0;


long  _lStartTime = 0;
eState_t _eState = UNKNOWN;

int utl_match(const char* s1, const char* s2, int iLen);
int dat_procRequest(char* aMsg, int iLen);
int com_recv(char* aBuf);

void setup() {

  /*
   * +++ //no line ending
   * AT+USBDEBUG=OFF //both nl cr
   * AT+BLUNODEBUG=OFF
   * AT+NAME=[]
   * AT+EXIT
   * +++
   */
  Serial.begin(115200);

  pinMode(DEPLOY_STATUS_PIN, OUTPUT);
  digitalWrite(DEPLOY_STATUS_PIN, LOW);

  pinMode(13, OUTPUT);

  _lStartTime = millis();
  sys_setState(INACTIVE);
  //sys_setState(IDLE);
  return;
}

void loop() {
  if (_bFirstActivate) {
    digitalWrite(DEPLOY_STATUS_PIN, HIGH);
    delay(50);
    digitalWrite(DEPLOY_STATUS_PIN, LOW);
    delay(50);
    digitalWrite(DEPLOY_STATUS_PIN, HIGH);
    delay(50);
    digitalWrite(DEPLOY_STATUS_PIN, LOW);
    _bFirstActivate = FALSE;
  }
  
  _iRecvIdx = 0;
  memset(_aRecvBuf, 0, sizeof(_aRecvBuf));

  int iRetVal = com_recv(_aRecvBuf);
  if (iRetVal == STATUS_FAILED) {
    delay(90);
    return;
  }

  if (iRetVal == STATUS_DATA_RECVD) {
    if (dat_procRequest(_aRecvBuf, _iRecvIdx) <= STATUS_FAILED) {
      // Failed
      return;
    }
  }

  if (_bLiveNotif) {
    if (dat_liveNotif() <= STATUS_FAILED) {
      // FAILED
      return;
    }
  }

  delay(90);
  if((_lStartTime + CATCH_QUERY_DURATION) < millis()){ 
    digitalWrite(DEPLOY_STATUS_PIN, HIGH);
    delay(500);
    digitalWrite(DEPLOY_STATUS_PIN, LOW);
    _bFirstActivate = TRUE;
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
    _lStartTime = millis();
  }
  return;
}

int com_recv(char* aBuf) {
  if (Serial.available() > 0) {
    _lStartTime = millis();
    char c = 1;
    while (c >= 0) {
      c = Serial.read();
      if ((c <= ' ') && (_iRecvIdx == 0)) {
        delay(50);
        continue;
      }
      _aRecvBuf[_iRecvIdx++] = c;
      delay(50);
    }
    return STATUS_DATA_RECVD;
  }

  return STATUS_OK;
}

int dat_respSensor() {
  char aBaseStr[64];
  char aValStrPH[10];
  char aValStrBatt[10];
  
  memset(aBaseStr, 0, sizeof(aBaseStr));
  memset(aValStrPH, 0, sizeof(aValStrPH));
  memset(aValStrBatt, 0, sizeof(aValStrBatt));
  // PH data
  int iAdcValPH = analogRead(PH_SENSOR_PIN);
//  float dValPH = (iAdcValPH * 5.0) / 1024;


  // Battery data
  int iAdcValBatt = analogRead(BATT_LEVEL_PIN);
//  float dValBatt = 2 * iAdcValBatt * 4.87 / (2.0 * 997.376);

  dtostrf(iAdcValPH, 6, 2, aValStrPH);
  dtostrf(iAdcValBatt, 6, 2, aValStrBatt);
  
  strcpy(aBaseStr, " RDATA: pH=");
  strcat(aBaseStr, aValStrPH);
  strcat(aBaseStr, ";");
  Serial.println(aBaseStr);
  
  strcpy(aBaseStr, " RDATA: bt=");
  strcat(aBaseStr, aValStrBatt);
  strcat(aBaseStr, ";");
  Serial.println(aBaseStr);
 
}
{'fraction_non_alphanumeric': 0.13315657681543674, 'fraction_numerical': 0.030343202238915894, 'mean_word_length': 3.3891402714932126, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3385216', 'n_tokens_mistral': 3025, 'n_tokens_neox': 2843, 'n_words': 552}