Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Ghassan Yusuf
#46106 Dear Friends

I am trying to build a tcp chat between 3 node mcu v3.

MCUs List And Role (Please See The Attachment)

1. Access Point + TCP Server
2. TCP Client With Blue Button & LED
3. TCP Client With Red Button & LED

now, this project should work as the following, when [1] is turned on it waits for clients to join. once [2] and or [3] turns on they directly locate the access point and joins each [2][3] will be assigned and ip address by the access point.

Scenario 1
if the tcp server send a signal with a content like <BLUE:ON>, the TCP Client With Blue button led will turn on else if <BLUE:OFF> the led will turn of, the same thing goes for the RED.

Scenario 2
if the client button was pressed it send a message to the TCP Server like <BLUE:PRESSED> or <BLUE:RELEASED>, then the TCP Server Will Write the same message to the serial port to VB.net application.

now i have been looking all over the internet for a similar situwation i couldent find. and i really dont know hoe to do it. i am using arduino ide to program the wifi node mcu. so please help me write the code.

my server code is not complete because i dont know and have no documentation on the WiFi Libraries see my code below

Code: Select all/* ---------------------------------------------------------------
 *  This Is An Access Point That Gives IP Addresses
 *  To WiFi Modules, Like Blue & Red
 ---------------------------------------------------------------*/

  // Importing Libraries
  #include <ESP8266WiFi.h>
  #include <WiFiClient.h>

  // Declaring Pins Constants
  #define     LED               D0    // LED Pin
  #define     BUTTON            D1    // Button Input
  #define     ANALOG            A0    // Analog Input
  #define     MAX_SRV_CLIENTS   2     // Max Number Of Clients
 
  // Set These To Your Credentials
  const char  *ssid       = "<TEST>";
  const char  *password   = "";
  const int   port        = 9001;
 
  // Creating TCP Server
  WiFiServer  TESTServer(9001);
  // Array Of Clients
  WiFiClient  TESTClients[MAX_SRV_CLIENTS];

//================================================================
//  Chip Setup
//================================================================
 
  void setup()
  {
    // Set IO Pins
    pinMode(LED, OUTPUT);
    pinMode(BUTTON, INPUT_PULLUP);
   
    // Important Delay
     delay(1000);
 
    // Setting Up Serial Communication
     Serial.begin(115200);
     Serial.println();
     Serial.println("Configuring Access Point . . .");
 
    // Starting Up The Access Point
     WiFi.softAP(ssid, password);
 
    // Declaring IP Address Object
     IPAddress IP = WiFi.softAPIP();
 
    // Printing IP Address
     Serial.print("Access Point IP Address : ");
     Serial.println(IP);
 
    // Starting Server
     TESTServer.begin();
    TESTServer.setNoDelay(true);
 
    // Print Message On The Screen
     Serial.println("TCP Server Started");
  }

//================================================================
// Running Program
//================================================================
 
  void loop()
  {


   
  }

//================================================================
// Subs & Functions
//----------------------------------------------------------------

  boolean Read(int Pin)
  {
    return digitalRead(BUTTON);
  }

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  void Light(int Pin)
  {
    digitalWrite(Pin, HIGH);
  }

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  void Dark(int Pin)
  {
    digitalWrite(Pin, LOW);
  }

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//================================================================
// End Of Program
//================================================================
You do not have the required permissions to view the files attached to this post.
User avatar
By markingle
#46119 I am trying to accomplish something very similar. My project is to create a simple security alarm with two Node MCU. First I need to code a "heart beat" function between two MCU. My first attempt was done using the ESP8266 Web Server lib but it was too clunky. I post any progress here as I work to get TCP comms working. There is not much documentation or examples for the Arduint IDE.
User avatar
By rastapapa
#46121 Would like to understand this as well. My application is having two ESP8266-12Es talk to each other over a local network. One esp sends the status of a momentary button. The other esp will turn on a simple mp3 player via a transistor on a output pin.

I think a simple tcp socket will work, but I'm not sure if it the router assigns a dynamic IP if it will still work. I don't think I can gain access to static IP addresses.