<commit_before>#include "relayr.h"

RelayrClient::RelayrClient() {}

WiFiClient wifi;

            
//define your mqtt credentials
#define DEVICE_ID "5abd9c5e-8ba2-4cd4-8695-a2debf8fab4b" 
#define MQTT_USER "<PASSWORD>" 
#define MQTT_PASSWORD "<PASSWORD>"
#define MQTT_CLIENTID "TWr2cXouiTNSGlaLev4+rSw" //can be anything else
#define MQTT_TOPIC "/v1/5abd9c5e-8ba2-4cd4-8695-a2debf8fab4b/"
#define MQTT_SERVER "mqtt.relayr.io"


char message_buff[100];

const String command = "set_temperature";
float commandValue;

void callback(char* topic, byte* payload, unsigned int length);
void handlePayload(char* message);
void (*clientCallback)(float message);

PubSubClient client(MQTT_SERVER, 1883, wifi);

// implement our callback method thats called on receiving data
void callback(char* topic, byte* payload, unsigned int length) {
  char p[length + 1];
  memcpy(p, payload, length);
  p[length] = 0;
  String message(p);
  //print the topic and the payload received
  Serial.println("topic: " + String(topic));
  Serial.println("payload: " + message);
  
  handlePayload(p);
}

void handlePayload(char* message) {  
  String msg = String(message);

  int matchIndex = msg.indexOf(command);
  if (matchIndex != -1) {
    String value = msg.substring(199, 203);
    char floatbuf[4];
    value.toCharArray(floatbuf, sizeof(floatbuf));
    float setTemp = atof(floatbuf);
    (*clientCallback)(setTemp);
  }
}


void wifi_connect(char* ssid, char* password) {<commit_msg>Lookup where the value in command message is<commit_after>#include "relayr.h"

RelayrClient::RelayrClient() {}

WiFiClient wifi;

            
//define your mqtt credentials
#define DEVICE_ID "5abd9c5e-8ba2-4cd4-8695-a2debf8fab4b" 
#define MQTT_USER "<PASSWORD>" 
#define MQTT_PASSWORD "<PASSWORD>"
#define MQTT_CLIENTID "TWr2cXouiTNSGlaLev4+rSw" //can be anything else
#define MQTT_TOPIC "/v1/5abd9c5e-8ba2-4cd4-8695-a2debf8fab4b/"
#define MQTT_SERVER "mqtt.relayr.io"


char message_buff[100];

const String command = "set_temperature";
const String valueKey = "value\":\"";

void callback(char* topic, byte* payload, unsigned int length);
void handlePayload(char* message);
void (*clientCallback)(float message);

PubSubClient client(MQTT_SERVER, 1883, wifi);

// implement our callback method thats called on receiving data
void callback(char* topic, byte* payload, unsigned int length) {
  char p[length + 1];
  memcpy(p, payload, length);
  p[length] = 0;
  String message(p);
  //print the topic and the payload received
  Serial.println("topic: " + String(topic));
  Serial.println("payload: " + message);
  
  handlePayload(p);
}

void handlePayload(char* message) {  
  String msg = String(message);

  int matchIndex = msg.indexOf(command);
  int valueIndex = msg.indexOf(valueKey);
  if (matchIndex != -1 && valueIndex != -1) {
    int valuePosition = valueIndex + valueKey.length();
    String value = msg.substring(valuePosition, valuePosition + 2);
    char floatbuf[4];
    value.toCharArray(floatbuf, sizeof(floatbuf));
    float setTemp = atof(floatbuf);
    (*clientCallback)(setTemp);
  }
}


void wifi_connect(char* ssid, char* password) {
{'fraction_non_alphanumeric': 0.1268775966762544, 'fraction_numerical': 0.02940236497283477, 'mean_word_length': 4.817843866171004, 'pattern_counts': {'":': 1, '<': 7, '<?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': '7530278', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1080, 'n_words': 269}