User Tools

Site Tools


arduinohouse

This is an old revision of the document!


https://forum.arduino.cc/t/arduino-433-mhz-rf-sending-numbers-instead-of-strings/619707/4 Looking at the loop() in the ask_transmitter example

void loop() {

  const char *msg = "hello";
  driver.send((uint8_t *)msg, strlen(msg));
  driver.waitPacketSent();
  delay(200);

}

There is a send() method; you can find that in C:\Users\yourUserName\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp and the first line is important.

bool RH_ASK::send(const uint8_t* data, uint8_t len)

and 'states' that the send method expects a pointer to an uint8_t (aka byte) variable and a length.

The line can also be found (in a slightly different form) in C:\Users\yourUserName\Documents\Arduino\libraries\RadioHead\RH_ASK.h (that's the file that you include at the top of the sketch).

So if you now go back to the example code, you will see (uint8_t *)msg ; this is a so-called cast that tells the compiler to treat the char array (msg) as a byte array.

So now you know that you actually need to send bytes and not characters etc. and how that's achieved.

To send an int value, you can cast the address of the variable (the pointer) to an pointer to a byte. An int occupies a number of bytes; you can find that with the sizeof operator.

That would look like

int waterPressure = 1234; drive.send1);

Because waterPressure is not an array, you need the & in front of it to get the address of the variable

https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-json

iminaries

JavaScript has only one data type which can contain multiple values: Object. An Array is a special form of object.

(Plain) Objects have the form

{key: value, key: value, …}

Arrays have the form

[value, value, …]

Both arrays and objects expose a key → value structure. Keys in an array must be numeric, whereas any string can be used as key in objects. The key-value pairs are also called the “properties”.

Properties can be accessed either using dot notation

const value = obj.someProperty;

or bracket notation, if the property name would not be a valid JavaScript identifier name [spec], or the name is the value of a variable:

the space is not a valid character in identifier names const value = obj[“some Property”]; property name as variable const name = “some Property”; const value = obj[name];

For that reason, array elements can only be accessed using bracket notation:

const value = arr[5]; arr.5 would be a syntax error property name / index as variable const x = 5; const value = arr[x];

nestedstruct
/*
 
var names = ["name1","another_name","any_anme_you_wish"];// list of names
var hold_obj = {};// `temp object
names.forEach ((v,i) => hold_obj[v] = msg.payload[i]) //loop through names and add to object
msg.payload = hold_obj; // move back to payload
return msg;
 

What JSON looks like

JSON is a human-readable format for storing and transmitting data. As the name implies, it was originally developed for JavaScript, but can be used in any language and is very popular in web applications. The basic structure is built from one or more keys and values:

{

"key": value

}

You’ll often see a collection of key:value pairs enclosed in brackets described as a JSON object. While the key is any string, the value can be a string, number, array, additional object, or the literals, false, true and null. For example, the following is valid JSON:

{

"key": "String",
"Number": 1,
"array": [1,2,3],	
"nested": {
"literals": true
}	

}

JSON doesn’t have to have only key:value pairs; the specification allows to any value to be passed without a key. However, almost all of the JSON objects that you see will contain key:value pairs.

1)
uint8_t*)&waterPressure, sizeof(waterPressure
arduinohouse.1684305693.txt.gz · Last modified: 2023/05/17 06:41 by admin