Skip to main content
4 of 5
added 305 characters in body
Thijs
  • 432
  • 1
  • 6
  • 22

Char Array Buffers String UINT8

So, I have an ATTiny85 sending data, awesome. I would like to have it send a message that consists of a few concatenated parts.

I have been reading about strings, buffers, chars, toCharArray and more for about 6 hours now and am completely puzzled by this.

Below, the variable deze will no transmit, but msg will. So I tried to do something like char *deze = "hello" + "world"; but that also fails.

What would be the best way to construct a piece of data that will be send by my 433MHz transmitter. I need to combine INT, String and float before sending it as uint8_t (bytes?).

#include <RH_ASK.h>

#define R_PIN PB4
#define T_PIN PB1
#define L_PIN PB3

RH_ASK driver(2000, R_PIN, T_PIN);

void setup()
{
  if (!driver.init()){
    pinMode(L_PIN, OUTPUT);
    digitalWrite(L_PIN, HIGH);
    delay(500);
    digitalWrite(L_PIN, LOW);
    delay(500);
  }
}

void loop()
{
  char deze[5];
  char *msg = "gewonechar";

  String thijs = "thijs";
  thijs.toCharArray(deze, sizeof(deze)-1);
  
  driver.send((uint8_t *)deze, strlen(msg));
  driver.waitPacketSent();
  delay(200);
}

[edit]
This is the receiving end, it receives partially correct data, a b it of a mess actually.

struct dataStruct{
  int id;
  float analog1;
  float analog2;
}myData;

void loop()
{
    uint8_t buflen = sizeof(buf);
    if (driver.recv(buf, &buflen)) {
      memcpy(&myData, buf, buflen);
      int i;
      // inbellen("http://api.thingspeak.com/update?api_key=PSD722OLDGYHJHM2&field1=" + String((char*)buf));
      Serial.print("Message: ");
      Serial.println(myData.analog1);
      Serial.println(myData.analog2);
      Serial.println(myData.id);
    }
    server.handleClient();
    yield();
}
Thijs
  • 432
  • 1
  • 6
  • 22