I would like to build a tcp chat between 3 node mcu v3
Posted: Sun Apr 24, 2016 4:42 pm
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
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
//================================================================