user58687: I am trying to send data between Arduino Nano and D1 Mini (ESP 8266 Module)
My Code as below in Nano which will be the transmeting ,
#include <DES.h>
#include <SoftwareSerial.h>
SoftwareSerial link(2, 3); // Rx, Tx
DES des;
byte in[8];
String  input;
char text[20];
char charVal[6];


char buf[30];
void setup() {
  link.begin(9600);
  Serial.begin(9600);
  Serial.println("Hello! Pleace Enter Your Data to Encrypt");

}

void tdesTest() {
  byte out[8];
  byte key[] = {
    0x3b, 0x38, 0x98, 0x37, 0x15, 0x20, 0xf7, 0x5e, // key A
    0x92, 0x2f, 0xb5, 0x10, 0xc7, 0x1f, 0x43, 0x6e, // key B
    0x3b, 0x38, 0x98, 0x37, 0x15, 0x20, 0xf7, 0x5e, // key C (in this case A)
  };

  Serial.println();
  Serial.println("====== Triple-DES test ======");

  //encrypt
  Serial.print("Encrypt...");
  unsigned long time = micros();
  des.tripleEncrypt(out, in, key);
  time = micros() - time;
  Serial.print("done. (");
  Serial.print(time);
  Serial.println(" micros)");
  printArray(out);
  /*
    //decrypt
    for (int i = 0; i < 8; i++)
    {
      in[i] = out[i];
    }
    Serial.print("Decrypt...");
    time = micros();
    des.tripleDecrypt(out, in, key);
    time = micros() - time;
    Serial.print("done. (");
    Serial.print(time);
    Serial.println(" micros)");
    printArray(out);
    delay(2000);
  */
}

//printing output
void printArray(byte output[])
{
  for (int i = 0; i < 8; i++)
  {
    if (output[i] < 0x10)
    {
      Serial.print("0");
    }
    Serial.print(output[i], HEX);
    Serial.print(" ");
    delay(100);

  }
  Serial.println();

}

void loop() {

  while (Serial.available() > 0) {

    String  input = Serial.readString(); // read the incoming data as string
    memset(in, 0, 9); // Erase the contents of in[]
    input.toCharArray((char *)in, 9); // Copy up to 8 bytes from the string
    tdesTest();


  }
}

In printArray(byte output[])I am getting Output as HEX Byte as below

I am trying to send the this encrypted data to from Arduino nano to D1 Mini,
I have wrote a small Receiver  Application in D1 Mini and It works ,
Receiver Code:
//Receiver code
#include <SoftwareSerial.h>
SoftwareSerial link(4, 0); // Rx, Tx

byte greenLED = 13;
char cString[2000];
byte chPos = 0;
byte ch = 0;
char dataStr[6];

void setup()
{
  link.begin(9600); //setup software serial
  Serial.begin(9600);    //setup serial monitor
  pinMode(greenLED, OUTPUT);
}

void loop()
{

  while (link.available())
  {
    ESP.wdtDisable();


    //read incoming char by char:
    ch = link.read();
    cString[chPos] = ch;
    chPos++;

    digitalWrite(greenLED, HIGH); //flash led to show data is arriving
    delay(20);
    digitalWrite(greenLED, LOW);

  }

  cString[chPos] = 0; //terminate cString
  chPos = 0;

  Serial.print(cString);
  ESP.wdtEnable(1);
  Serial.flush();

}

I want to pass this HEX data Generated to D1 Mini from Arduino Nano,
I have wrote test code in Arduino Nano for Transmitter(Nano) and between Receiver (D1 Mini) it works,
//Transmitter Code for Testing Connections
#include <SoftwareSerial.h>
SoftwareSerial link(2, 3); // Rx, Tx
byte greenLED = 12;
char text[20] ;
char charVal[6];

void setup()
{
  link.begin(9600);
  Serial.begin(9600);

}

void loop()
{
  strcat(text, "Message"); //append to empty string
  Serial.println(text); //print to local screen for debug*
  link.println(text);

  delay(10000);
}

Please help me to send this HEX data in single shot to D1 Mini.


user37622: You can change your printArray function to work on provided Print instance:
void printArray(byte output[], Print& serial)
{
  for (int i = 0; i < 8; i++)
  {
    if (output[i] < 0x10)
    {
      serial.print("0");
    }
    serial.print(output[i], HEX);
    serial.print(" ");
  }
  serial.println();

}

then you can use it as printArray(out, Serial); or printArray(out, link);.

58687: <p>I am trying to send data between Arduino Nano and D1 Mini (ESP 8266 Module)</p>
<p><em>My Code as below in Nano which will be the transmeting ,</em></p>
<pre><code>#include &lt;DES.h&gt;
#include &lt;SoftwareSerial.h&gt;
SoftwareSerial link(2, 3); // Rx, Tx
DES des;
byte in[8];
String  input;
char text[20];
char charVal[6];


char buf[30];
void setup() {
  link.begin(9600);
  Serial.begin(9600);
  Serial.println(&quot;Hello! Pleace Enter Your Data to Encrypt&quot;);

}

void tdesTest() {
  byte out[8];
  byte key[] = {
    0x3b, 0x38, 0x98, 0x37, 0x15, 0x20, 0xf7, 0x5e, // key A
    0x92, 0x2f, 0xb5, 0x10, 0xc7, 0x1f, 0x43, 0x6e, // key B
    0x3b, 0x38, 0x98, 0x37, 0x15, 0x20, 0xf7, 0x5e, // key C (in this case A)
  };

  Serial.println();
  Serial.println(&quot;====== Triple-DES test ======&quot;);

  //encrypt
  Serial.print(&quot;Encrypt...&quot;);
  unsigned long time = micros();
  des.tripleEncrypt(out, in, key);
  time = micros() - time;
  Serial.print(&quot;done. (&quot;);
  Serial.print(time);
  Serial.println(&quot; micros)&quot;);
  printArray(out);
  /*
    //decrypt
    for (int i = 0; i &lt; 8; i++)
    {
      in[i] = out[i];
    }
    Serial.print(&quot;Decrypt...&quot;);
    time = micros();
    des.tripleDecrypt(out, in, key);
    time = micros() - time;
    Serial.print(&quot;done. (&quot;);
    Serial.print(time);
    Serial.println(&quot; micros)&quot;);
    printArray(out);
    delay(2000);
  */
}

//printing output
void printArray(byte output[])
{
  for (int i = 0; i &lt; 8; i++)
  {
    if (output[i] &lt; 0x10)
    {
      Serial.print(&quot;0&quot;);
    }
    Serial.print(output[i], HEX);
    Serial.print(&quot; &quot;);
    delay(100);

  }
  Serial.println();

}

void loop() {

  while (Serial.available() &gt; 0) {

    String  input = Serial.readString(); // read the incoming data as string
    memset(in, 0, 9); // Erase the contents of in[]
    input.toCharArray((char *)in, 9); // Copy up to 8 bytes from the string
    tdesTest();


  }
}
</code></pre>
<p>In <code>printArray(byte output[])</code>I am getting Output as <code>HEX</code> Byte as below</p>
<p><a href="https://i.stack.imgur.com/1lefo.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1lefo.jpg" alt="enter image description here" /></a></p>
<p><strong>I am trying to send the this encrypted data to from Arduino nano to D1 Mini,</strong></p>
<p>I have wrote a small Receiver  Application in D1 Mini and It works ,
<em>Receiver Code:</em></p>
<pre><code>//Receiver code
#include &lt;SoftwareSerial.h&gt;
SoftwareSerial link(4, 0); // Rx, Tx

byte greenLED = 13;
char cString[2000];
byte chPos = 0;
byte ch = 0;
char dataStr[6];

void setup()
{
  link.begin(9600); //setup software serial
  Serial.begin(9600);    //setup serial monitor
  pinMode(greenLED, OUTPUT);
}

void loop()
{

  while (link.available())
  {
    ESP.wdtDisable();


    //read incoming char by char:
    ch = link.read();
    cString[chPos] = ch;
    chPos++;

    digitalWrite(greenLED, HIGH); //flash led to show data is arriving
    delay(20);
    digitalWrite(greenLED, LOW);

  }

  cString[chPos] = 0; //terminate cString
  chPos = 0;

  Serial.print(cString);
  ESP.wdtEnable(1);
  Serial.flush();

}
</code></pre>
<p><strong>I want to pass this HEX data Generated to D1 Mini from Arduino Nano,</strong></p>
<p>I have wrote test code in Arduino Nano for <em>Transmitter</em>(Nano) and between <em>Receiver</em> (D1 Mini) it works,</p>
<pre><code>//Transmitter Code for Testing Connections
#include &lt;SoftwareSerial.h&gt;
SoftwareSerial link(2, 3); // Rx, Tx
byte greenLED = 12;
char text[20] ;
char charVal[6];

void setup()
{
  link.begin(9600);
  Serial.begin(9600);

}

void loop()
{
  strcat(text, &quot;Message&quot;); //append to empty string
  Serial.println(text); //print to local screen for debug*
  link.println(text);

  delay(10000);
}
</code></pre>
<p>Please help me to send this <strong><code>HEX</code></strong> data in single shot to D1 Mini.
<a href="https://i.stack.imgur.com/0YNWU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0YNWU.jpg" alt="enter image description here" /></a></p>
 37622: <p>You can change your <code>printArray</code> function to work on provided <code>Print</code> instance:</p>
<pre><code>void printArray(byte output[], Print&amp; serial)
{
  for (int i = 0; i &lt; 8; i++)
  {
    if (output[i] &lt; 0x10)
    {
      serial.print(&quot;0&quot;);
    }
    serial.print(output[i], HEX);
    serial.print(&quot; &quot;);
  }
  serial.println();

}
</code></pre>
<p>then you can use it as <code>printArray(out, Serial);</code> or <code>printArray(out, link);</code>.</p>
