Sending serial data from serial monitor of one Ameba to another.

Hi ,

I want to send user input data from the serial monitor of one Ameba to be received and displayed in another arduino. My code for sender side is as follows:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>

char ssid[] = "ESPAP";      //  your network SSID (name)
char password[] = "mPass@54321";  //Set the AP's password
unsigned int localPort = 2390;        // local port to listen on
#define LOOP_DELAY    100             //how fast we check for new data
#define ARRAYSIZE     255             //size of message array (255bytes)
#define BAUD_RATE     115200          //serial comunication speed
IPAddress remoteIp;
int remoteUDPPort;
char packetBuffer[ARRAYSIZE]; //buffer to hold incoming packet
int arraySize = ARRAYSIZE;
char inData[ARRAYSIZE]; // Allocate some space for the string
char inChar; // Where to store the character read
byte aindex = 0; // Index into array; where to store the character
boolean dataToSend = false;
WiFiUDP Udp;
void setup()
{
  delay(100);
  Serial.begin(BAUD_RATE);
  WiFi.softAP(ssid, password);    //Start AP
  Udp.begin(localPort);
}
void loop() {
  while (Serial.available() > 0) //check for something to read from serial port
  {
    if (aindex < (arraySize - 1)) // One less than the size of the array
    {
      inChar = Serial.read();   // Read a character
      inData[aindex] = inChar;  // Store it
      aindex++;                 // Increment where to write next
      inData[aindex] = '\0';    // Null terminate the string
    }
    dataToSend = true;
  }
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  int len = Udp.read(packetBuffer, 255);
  if (len > 0) {
    packetBuffer[len] = 0;
  }
  Serial.println(packetBuffer);
 if(dataToSend)
  {
    if(Udp.beginPacket(remoteIp, remoteUDPPort))
    {
      Udp.write(inData);
      Udp.endPacket();
    }
    dataToSend = false; //set the flag to false, ie only send when you need to.
    for (aindex=0; aindex < arraySize; aindex++)  //wipe the array
    {
       inData[aindex] = '\0'; // Null terminate the string
    }
    aindex = 0; //reset the index
  }
    delay(LOOP_DELAY); // slow the process doown
}

The portion of code for receiving this data is as follows:

void loop()
{
//check for incoming data via UDP
int packetSize = Udp.parsePacket();
int len = Udp.read(packetBuffer, 255);
if (len > 0){
packetBuffer[len] = 0;
}
Serial.println(packetBuffer);
[/code]
The entire code at receiver side is attached as well. The image attached shows the serial string data to be sent from the sending side. pls help, thanks a lot

All_Sensors_Wireless.ino (12.5 KB)

What's an Ameba?

And what's your problem? What does the code do? What do you expect it to do?

Ameba RTL8195 is an arduino like microcontroller with wifi capabilities. full details :
https://www.amebaiot.com/en/

Im using this to get measurements from 5 sensors and then sending it via UDP to ESP8266 (acting as AP) which displays those readings on its serial monitor and its already achieved. Now, i want to be able to send some text from ESP8266 back to Ameba from the serial monitor of ESP8266. For that im using this part of code on my ESP8266:

 while (Serial.available() > 0) //check for something to read from serial port
  {
    if (aindex < (arraySize - 1)) // One less than the size of the array
    {
      inChar = Serial.read();   // Read a character
      inData[aindex] = inChar;  // Store it
      aindex++;                 // Increment where to write next
      inData[aindex] = '\0';    // Null terminate the string
    }
    dataToSend = true;
  }

and later sending as :

if(dataToSend)
  {
   Udp.beginPacket(remoteIp, remoteUDPPort);
      Udp.write(inData);
      Udp.endPacket();
    dataToSend = false; //set the flag to false, ie only send when you need to.
    for (aindex=0; aindex < arraySize; aindex++)  //wipe the array
    {
       inData[aindex] = '\0'; // Null terminate the string
    }
    aindex = 0; //reset the index
  }

sal_murd:
Ameba RTL8195 is an arduino like microcontroller with wifi capabilities. full details :
https://www.amebaiot.com/en/

I can't see any technical information on that link to tell us what hardware is on that device. Like a lot of recent product websites it is just fancy pictures.

...R

They all seem to have "Cotex" processors :o
Leo..

Wawa:
They all seem to have "Cotex" processors :o
Leo..

That sort of error does not inspire confidence.

...R

Be glad they did not spell Cotex with a K :smiley:

OP:
I've tried to read your code
but the indentation
is so piss-poor
that I get a headache
trying to
follow the logic.
It is SO freaking simple to use Tools + Auto Format to remove the illusion that your code was typed by a drunken monkey.

Forget about the serial monitor. That is where the ESP currently sends serial data. THAT is useless information. It's history. You can't retrieve what you sent there, any more than you can retrieve the water you poured down the drain.

What information do you want the ESP to send, and where do you want it sent?

PaulS:
OP:
I've tried to read your code
but the indentation
is so piss-poor
that I get a headache
trying to
follow the logic.
It is SO freaking simple to use Tools + Auto Format to remove the illusion that your code was typed by a drunken monkey.

Forget about the serial monitor. That is where the ESP currently sends serial data. THAT is useless information. It's history. You can't retrieve what you sent there, any more than you can retrieve the water you poured down the drain.

What information do you want the ESP to send, and where do you want it sent?

Usually I dont get any idea from your response, poor, arrogant and mostly nonsense stuff . If you get headache, just leave it; dont become a drunken monkey.

For the ESP, i wanted it to read from the serial interface and send to a remote arduino for what I type in the serial monitor next to the send button, that is very simple English. It has now been accomplished.