How to Convert a Char Array on a uint16_t Array

Hi Team, I am testing a code to receive the IR codes from a central site via socket and send it through an IR led using the irsend.sendRaw option.

Today I program the raw data on the Arduino but I want to receive this code from a central controller, in my case a Raspberry PI, using readBytesUntil, which returns a char.

I receive, via socket:

char bosup[72] = {1000,1500,550,1450,500,450,500,500,500,450,550,450,500,1450,550,1450,500,1500,500,500,500,1450,500,1450,550,1450,600,1350,550,450,500,500,500,500,500,};

as a char, and I need it to be:

uint16_t bosup[72] = {1000,1500,550,1450,500,450,500,500,500,450,550,450,500,1450,550,1450,500,1500,500,500,500,1450,500,1450,550,1450,600,1350,550,450,500,500,500,500,500,};

To send via the

irsend.sendRaw(bosup,72,38);
command.

Can you help me on that? I not even close to a C programmer so if you can help me as a beginer I would appreciate a lot!

Thanks in advance and very best regards,

char bosup[72] = {1000,1500,550,1450,500,450,500,500,500,450,550,450,500,1450,550,1450,500,1500,500,500,500,1450,500,1450,550,1450,600,1350,550,450,500,500,500,500,500,};

That will not work as a char type cannot hold a value of 1000.

Please post your current code so we see how you get these values. If necessary to understand the code please also post the correspondent code on the Raspberry Pi.

Sure, here is the simple code I use to test the connection from the PI, send the string I need through net cat “nc” and receive it at the “received” char variable.

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#ifndef UNIT_TEST
#include <Arduino.h>
#include <stdlib.h>
#endif
#include <IRremoteESP8266.h>
#include <IRsend.h>
#define RAWBUF 300
#define _GAP 50000
IRsend irsend(14);
//
// Configuration:
#define WIFI_NAME “HomeOffice”
#define WIFI_PASSWORD “T5c3p1da…”
#define SERVER_PORT 5000
#define SERVER_NAME “ucsirsala10”
#define PI_ADDRESS “192.168.0.150”
//
WiFiServer server(SERVER_PORT);
//
void setup() {
Serial.begin(115200);
delay(10);

// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(WIFI_NAME);

WiFi.begin(WIFI_NAME, WIFI_PASSWORD);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println(“WiFi connected”);

// Start the server
server.begin();
Serial.println(“Server started”);

// Print the IP address
Serial.println(WiFi.localIP());

// Setup mDNS responder.
if (!MDNS.begin(SERVER_NAME)) {
Serial.println(“Error setting up MDNS responder!”);
while(1) {
delay(1000);
}
}
}
//
void loop() {
WiFiClient client = server.available();
if (!client) {
}
#define RECEIVED_SIZE 1800
char received[RECEIVED_SIZE] = {0};
if (client.readBytesUntil(’\n’, received, RECEIVED_SIZE-1) == 0) {
client.println(“ERROR: Timeout!”);
client.flush();
return;
}
Serial.print("Received: ");
Serial.println(received); // this is where I get the string I mentioned - I send it via net cat command
//
//
uint16_t caron24[200] = {4400,4300,550,1600,550,550,550,1600,550,1600,550,550,550,500,550,1650,500,550,550,550,550,1600,550,550,550,550,500,1650,550,1600,550,550,500,1650,550,1600,550,550,550,1600,550,1600,550,1600,550,1600,550,1650,500,1650,550,550,500,1650,500,550,550,550,550,550,500,600,500,550,550,550,500,550,550,1650,500,550,550,550,550,550,500,550,550,550,550,550,500,1650,550,500,550,1650,550,1600,550,1600,550,1600,550,1600,550,1600,550,5200,4400,4300,550,1600,550,550,500,1650,550,1600,550,550,550,500,550,1650,500,550,550,550,550,1600,550,550,550,500,600,1600,550,1600,550,500,600,1600,550,1600,550,550,550,1600,550,1600,550,1600,600,1550,600,1600,500,1650,550,500,550,1650,500,550,550,550,550,550,550,500,600,500,550,550,500,550,550,1600,600,500,550,550,550,500,600,500,550,550,550,500,600,1600,550,500,600,1600,550,1600,550,1600,550,1600,550,1600,600,1550,550,};
//irsend.sendRaw(caron24,200,38);
//
delay(200);
//
client.flush();
}

====================================

The net cat comand is formed as follows:

‘echo ’ + IRCommandFinal + ’ |’ + ’ nc ’ + sensorID + ’ 5000’

====================================

I printed the output I received and attached the file here.

What I want is use the " receive" char in the:

irsend.sendRaw(caron24,200,38);

Thanks!

serial print output.txt (949 Bytes)

Please read the post at the top of the Forum by Nick Gammon on the proper way to post source code using code tags. You do realize that you are storing your data as 16-bit integers and not 8-bit chars, right?

Thanks for the advise. I'll look after Nick's post.

You mean the " uint16_t caron24[200] = {4400,4300,550,1600,550,550..." part as a 16-bit interger?

If yes, this is what I need as a result of the transformation I need from the stream of characters I receive, as I explained.

Thanks,

jgouy:
Thanks for the advise. I'll look after Nick's post.

I suspect that @econjack was hoping you would read the link he gave you (and act on it) BEFORE you posted Reply #4

...R