Skip to main content
updated receiver and transmitter and included link to library used
Source Link
Thijs
  • 432
  • 1
  • 6
  • 22

[edit]
This is the receiving end, it receives partially correct data, a b it of a mess actuallyworking code on the receiver side.

struct dataStructdata {
  intuint16_t id;
  floatuint16_t analog1;pin;
  floatuint16_t analog2;value1;
  uint16_t value2;
} myData;
    
void loop()
{
    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
    uint8_t buflen = sizeof(buf); 

    if (driver.recv(buf, &buflen)) {
     
      memcpy(&myData, buf, buflen);
      int i;
      // inbellenSerial.print("http"ID://api "); 
      Serial.thingspeakprintln(myData.com/update?api_key=PSD722OLDGYHJHM2&field1="id);

 + String    Serial.print("Pin: "); 
      Serial.println(char*myData.pin)buf;

      Serial.print("Value1: "); 
      Serial.println(myData.value1); 

      Serial.print("Message"Value2: "); 
      Serial.println(myData.analog1value2);
      
      Serial.println(myData"");
    }
    server.analog2handleClient();
    yield;
}

And the transmitter

#include <RH_ASK.h>

#define BAUD 2000
#define RX 11
#define TX 12

RH_ASK driver(BAUD, RX, TX);

struct data {
  uint16_t id;
  uint16_t pin;
  uint16_t value1;
  uint16_t value2;
} myData;

void setup() {
    Serial.begin(9600);   // Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

void loop()
{
    struct data myData;

    myData.id = 1001;
    myData.pin = 4;
    myData.value1 = analogRead(4);
    }myData.value2 = analogRead(5);
    server
    driver.handleClientsend((uint8_t *)&myData, sizeof(myData));
    yielddriver.waitPacketSent();
    delay(2000);
}

Library used: http://www.airspayce.com/mikem/arduino/RadioHead/

[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();
}

[edit]
This is the working code on the receiver side.

struct data {
  uint16_t id;
  uint16_t pin;
  uint16_t value1;
  uint16_t value2;
} myData;
    
void loop()
{
    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
    uint8_t buflen = sizeof(buf); 

    if (driver.recv(buf, &buflen)) {
     
      memcpy(&myData, buf, buflen);
      
      Serial.print("ID: "); 
      Serial.println(myData.id);

      Serial.print("Pin: "); 
      Serial.println(myData.pin);

      Serial.print("Value1: "); 
      Serial.println(myData.value1); 

      Serial.print("Value2: "); 
      Serial.println(myData.value2);
      
      Serial.println("");
    }
    server.handleClient();
    yield;
}

And the transmitter

#include <RH_ASK.h>

#define BAUD 2000
#define RX 11
#define TX 12

RH_ASK driver(BAUD, RX, TX);

struct data {
  uint16_t id;
  uint16_t pin;
  uint16_t value1;
  uint16_t value2;
} myData;

void setup() {
    Serial.begin(9600);   // Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

void loop()
{
    struct data myData;

    myData.id = 1001;
    myData.pin = 4;
    myData.value1 = analogRead(4);
    myData.value2 = analogRead(5);
    
    driver.send((uint8_t *)&myData, sizeof(myData));
    driver.waitPacketSent();
    delay(2000);
}

Library used: http://www.airspayce.com/mikem/arduino/RadioHead/

added 305 characters in body
Source Link
Thijs
  • 432
  • 1
  • 6
  • 22

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 works but may be very wrong to do :)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()
{
  char analog[4];
 uint8_t charbuflen bericht[10];= sizeof(buf);
    if (driver.recv(buf, &buflen)) {
  strcpy    memcpy(bericht&myData, "thijs"buf, buflen);
      int i;
  float lezing = analogRead // inbellen(PB3"http://api.thingspeak.com/update?api_key=PSD722OLDGYHJHM2&field1=" + String((char*)buf));
  itoa(lezing, analog, 10  Serial.print("Message: ");
  
   strcat(bericht, analog Serial.println(myData.analog1);
 
  driver    Serial.send(println(uint8_t *myData.analog2)bericht,;
 strlen     Serial.println(bericht)myData.id);
  driver  }
    server.waitPacketSenthandleClient();
  delay  yield(200);
}

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 works but may be very wrong to do :)

void loop()
{
  char analog[4];
  char bericht[10];
  
  strcpy(bericht, "thijs");
  
  float lezing = analogRead(PB3);
  itoa(lezing, analog, 10);
  
   strcat(bericht, analog);
 
  driver.send((uint8_t *)bericht, strlen(bericht));
  driver.waitPacketSent();
  delay(200);
}

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();
}

Char Array Buffers String UNINT8UINT8

added 415 characters in body
Source Link
Thijs
  • 432
  • 1
  • 6
  • 22
Loading
Source Link
Thijs
  • 432
  • 1
  • 6
  • 22
Loading