User Tools

Site Tools


arduinohouse

Table of Contents

you need the process that monitors your process to be the process' parent. What does this mean? It means only the process that starts your process can reliably wait for it to end. In bash, this is absolutely trivial.

until myserver; do

  echo "Server 'myserver' crashed with exit code $?.  Respawning.." >&2
  sleep 1

done

The above piece of bash code runs myserver in an until loop. The first line starts myserver and waits for it to end. When it ends, until checks its exit status. If the exit status is 0, it means it ended gracefully (which means you asked it to shut down somehow, and it did so successfully). In that case we don't want to restart it (we just asked it to shut down!). If the exit status is not 0, until will run the loop body, which emits an error message on STDERR and restarts the loop (back to line 1) after 1 second.

Why do we wait a second? Because if something's wrong with the startup sequence of myserver and it crashes immediately, you'll have a very intensive loop of constant restarting and crashing on your hands. The sleep 1 takes away the strain from that.

Now all you need to do is start this bash script (asynchronously, probably), and it will monitor myserver and restart it as necessary. If you want to start the monitor on boot (making the server “survive” reboots), you can schedule it in your user's cron(1) with an @reboot rule. Open your cron rules with crontab:

crontab -e

Then add a rule to start your monitor script:

@reboot /usr/local/bin/myservermonitor

Alternatively; look at inittab(5) and /etc/inittab. You can add a line in there to have myserver start at a certain init level and be respawned automatically.


https://forum.arduino.cc/t/433mhz-using-radiohead-constructor-argument-to-change-rx-tx-pins/1077731 radiohead tx pin

https://startingelectronics.org/tutorials/arduino/digispark/digispark-windows-setup/ digispark setup

https://www.instructables.com/Receiving-and-sending-data-between-Attiny85/ attiny setup

https://github.com/adidax/dht11 dht11 library download

https://www.makerguides.com/dht11-dht22-arduino-tutorial/ humidity sensor on attiny

https://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-an-arduino/ humidity sensor on attiny

https://triq.org/rtl_433/STARTING.html rtl433 getting started

https://nodered.org/docs/user-guide/editor/workspace/import-export exporting nodered flows


https://lastminuteengineers.com/433mhz-rf-wireless-arduino-tutorial/ arduino 433 transmitters and receivers

https://forum.arduino.cc/t/sending-arrays-with-manchester-h-and-rf433/257585 manchester.h arrays

https://reference.arduino.cc/reference/en/language/variables/data-types/array/ arduino array reference

int myInts[6];
int myPins[] = {2, 4, 8, 3, 6};
int mySensVals[5] = {2, 4, -8, 3, 2};
char message[6] = "hello";

——————————————————————–

https://stackoverflow.com/questions/16041191/filling-array-in-c-by-using-functions

Arrays filling


https://triq.org/rtl_433/OPERATION.html

https://www.airspayce.com/mikem/arduino/RadioHead/ask_transmitter_8pde-example.html radiohead ASK transmitter

https://randomnerdtutorials.com/rf-433mhz-transmitter-receiver-module-with-arduino/ arduino receive/transmit

https://github.com/merbanan/rtl_433 rtl433 download

https://tech.sid3windr.be/2017/03/getting-your-currentcost-433mhz-data-into-openhab-using-an-rtl-sdr-dongle-and-mqtt/

  currentcost and mqtt rtl433
  
  

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];


ask_transmitter.pde -*- mode: C++ -*- Simple example of how to use RadioHead to transmit messages with a simple ASK transmitter in a very simple way. Implements a simplex (one-way) transmitter with an TX-C1 module #include <RH_ASK.h> #include <SPI.h> Not actually used but needed to compile

RH_ASK driver;

struct dataStruct{

float press_norm ; 
float press_hg;
float temp;
unsigned long counter;
 

}myData;

byte tx_buf[sizeof(myData)] = {0};

void setup() {

  Serial.begin(9600);	  // Debugging only
  if (!driver.init())
       Serial.println("init failed");
       
 myData.press_norm=1000.11; 

myData.press_hg=0.59; myData.temp=22.394;

}

void loop() {

memcpy(tx_buf, &myData, sizeof(myData) );
byte zize=sizeof(myData);

driver.send2);

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


arduino string example

https://arduinojson.org/v6/example/string/


1)
uint8_t*)&waterPressure, sizeof(waterPressure
2)
uint8_t *)tx_buf, zize);
 // driver.send((uint8_t *)msg, strlen(msg));
  driver.waitPacketSent();
  myData.counter++;
  delay(2000);
}
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
}	
}
Sorry to nitpick but Json object is not a thing. JSON is a string representation of a JavaScript object. Ok, enough of that :slight_smile: Use a function node, loop through the elements & add properties to an object…
var arr = msg.payload; // get the array
var rv = {};// create a new empty object
for (var i = 0; i < arr.length; ++i) {
  let key = "Val"+(i+1); //built a key 
  rv[key] = arr[i]; // set value in New object
}
msg.payload = nv;
return msg;
There are other, more modern/compact ways to achieve this but I kept it simple for clarity. Disclaimer: the above code is untested/off the top of my head. :innocent: Solution jackie7 May '21 Thank you for the clarification! I'm able to parse the array and get the values but I want to assign names to them, each value has a different name. how can I change their names from Val1 Val2…? Steve-Mcl May '21
  each value has a different name. how can I change their names from Val1 Val2.
unless you tell me what they are I cannot really help. an array is just a group of values. If you know which element is which item & they are always in the same place & there are always a fixed number of elements in the array, you can simply set them manually in the object. However, there may be a better solution - we should look at that first. Where does this array come from? can you show me how this array is generated? E1cid jackie7 May '21 You would need to list the names 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; assuming the array is in msg.payload. 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.
https://stevesnoderedguide.com/node-red-http-request-node-beginners nodered publish json : video3
https://discourse.nodered.org/t/http-post-with-parameter-and-body/21132/2 Try using below code inside a function node. Of course you want to replace the data otherwise the API will not authenticate. The HTTP request node should have the Method field configured as “-set by msg.method-” msg.headers = {} msg.method = “POST” msg.url = “https://arche.webuntis.com/WebUntis/jsonrpc.do” ; msg.headers[“content-type”] = “application/json” msg.payload = { “id”:“ID”, “method”:“authenticate”, “params”: { “user”:“xy”, “password”:“PASSWORD”, “client”:“CLIENT” }, “jsonrpc”:“2.0” };
https://www.tutorialspoint.com/structs-in-arduino-program Example The following example illustrates this − struct student{
 String name;
 int age;
 int roll_no;
}; void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);
 Serial.println();
 student A = {"Yash", 25, 26};
 Serial.println(A.name);
 Serial.println(A.age);
 Serial.println(A.roll_no);
 A.age = 27;
 Serial.println(A.age);
} void loop() {
 // put your main code here, to run repeatedly:
}
https://forum.arduino.cc/t/arduino-433-mhz-rf-sending-numbers-instead-of-strings/619707/3 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.send((uint8_t*)&waterPressure, sizeof(waterPressure
arduinohouse.txt · Last modified: 2023/05/17 09:28 by admin