Send udp packet

i want to send a udp packet to mt brightsign that is connected locally,
i serched op previous topics but i didn’t find anything related at all.
it whould be amazing if someone could show me an example of how to do it.
im using arduino mega with esp 8622 and blynk cloud server
best regards ,
Teddy

#define BLYNK_TEMPLATE_ID "############"
#define BLYNK_DEVICE_NAME "############"
#define BLYNK_AUTH_TOKEN "############"
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "SSID NAME";
char pass[] = "SSID PASS";
#define EspSerial Serial1
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);

BLYNK_WRITE(V1)
{
  if(param.asInt()==1){
    Serial.println("Start ON");
    StartGame();
  }
  else Serial.println("Start OFF");
}

BLYNK_CONNECTED()
{
  Blynk.syncAll();
}

void setup()
{
  Serial.begin(115200);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);
}

void loop()
{
  Blynk.run();   
}
void StartGame(){
  // here i want to send a udp packet to 10.0.0.250 on port 5000 with value "st" 
}

I doubt very much whether you’ll be able to do it with that hardware, because of the way in which the BlynkSimpleShieldEsp8266.h library communicates with the ESP8266 (using AT commands).

If you can find a working sketch for a standalone ESP8266/NodeMCU or ESP32 then it should be fairly simple to add Blynk into that code.

Pete.

hi Pete , thanks for the quick response .
i’ve managed to make a quick test skecth , not with blynk , and it worked .
how can i mirgate it with blynk ?


#include <WiFiEsp.h>
#include <WiFiEspUDP.h>

// ********************************************************* DEFINITIONS *********************************************************
char ssid[] = "inside_out_1";
char pass[] = "515446607";
int status = WL_IDLE_STATUS;

// IP address to send UDP data to.
unsigned int localport = 5000;
IPAddress remoteIP(10,0,0,250);
unsigned int remotePort = 5000;

WiFiEspUDP Udp;

void setup() {
  Serial.begin(115200);
  Serial1.begin(115200);
  WiFi.init(&Serial1);
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    while (true);
  }
  while ( status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to WPA SSID: "); 
    Serial.println(ssid);                   
    status = WiFi.begin(ssid, pass);
  }
  Serial.println("You're connected to the network");
  delay(1000);
  Serial.println();
  printCurrentNet();
  printWifiData();
  Udp.begin(localport);
}

void loop()
{
  Udp.beginPacket(remoteIP, remotePort);
  Udp.println("st");
  Serial.println("st");
  Udp.endPacket();
  delay(10000);
  Udp.println("reset");
  delay(10000);
  
}


void printWifiData()
{
  // *** print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // *** print your MAC address
  byte mac[6];
  WiFi.macAddress(mac);
  char buf[20];
  sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
  Serial.print("MAC address: ");
  Serial.println(buf);
}

// Print WiFi connection details to serial Monitor  --------------------------------------------------------
void printCurrentNet()
{
  // *** print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // *** print the MAC address of the router you're attached to
  byte bssid[6];
  WiFi.BSSID(bssid);
  char buf[20];
  sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[5], bssid[4], bssid[3], bssid[2], bssid[1], bssid[0]);
  Serial.print("BSSID: ");
  Serial.println(buf);

  // *** print the received signal strength
  long rssi = WiFi.RSSI();
  Serial.print("Signal strength (RSSI): ");
  Serial.println(rssi);
}

What hardware do you have this working on?

Pete.

hi Pete,
its working with the same hardware that i ran in blynk
arduino mega with ESP8266

Pete.

hey pete , so with what hardware do you think it will work ?

Maybe you should re-read what I wrote in post#2, rather than keep asking questions that I’ve already answered.

Pete.

Hey Pete, let me rephrase my word ,
the second sketch i atacjed works great and send the udp string that i want to my brightsign with arduino mega and esp8266 ,
the problam starts when i try to use the udp send command in blynk app
from you i understood that i can add the blynk to a working stenalone skecth (the sketch that i sent you before ), but i am having trouble adding the blynk into that code .

the final resoult that i whould like is that when i press button in blynk app it will send a udp command to my brightsign.

sorry for my bad english .

The Arduino Uno/Nano/Mega with an ESP8266 as the WiFi adapter is not a suitable platform to use.
This is because of the way that the BlynkSimpleShieldEsp8266.h library communicates with the ESP8266. Attempting to use the WiFi connection created by the BlynkSimpleShieldEsp8266.h library for UDP transmissions will not work.

However, if you used different hardware, such as an ESP8266 based board (a NodeMCU, Wemos D1 Mini or possibly even an ESP-01) or an ESP332 then a different Blynk library is used, which exposes the WiFi object for use by a UDP library.

Or, to summarise that…

Pete.

hey pete, thanks for the explanation ,
if i use mega2560 with ethernet shiled w5500 instead of esp8266 module ,
will it work ?

Maybe, although the Arduino Ethernet shields are generally more trouble than they are worth (and cost more than a NodeMCU).

Pete.