Help me : communication between S7 1200 and arduino mix Blynk

Hello!

  • I have a communication project between PLC (s7 1200), (Arduino + Ethernet shield) and Android.
  • The type of communication between PLC and ( Arduino + Ethernet shield) is Modbus TCP.
    The type of communication between (Arduino + Ethernet shield) and Android is Blynk.
    But I can not match Blynk code and Modbus TCP code on an Arduino. Despite no error, but modbus TCP not run . Please help me. Thank you!
    This is my code (arduino) :

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include “Mudbus.h”

Mudbus Mb;
char auth[] = “my token”;

#define W5100_CS 10
#define SDCARD_CS 4

BlynkTimer timer;
unsigned char val;
void sendSensor()
{

Blynk.virtualWrite(V6, int(analogRead(A0) * 0.48828125));

Blynk.virtualWrite(V7, int(analogRead(A1) * 0.48828125));
Blynk.virtualWrite(V8, int(analogRead(A1) * 0.48828125));
Blynk.virtualWrite(V9, int(analogRead(A2) * 0.48828125));
Blynk.virtualWrite(V10, int(analogRead(A3) * 0.48828125));
Blynk.virtualWrite(V11, int(analogRead(A4) * 0.48828125));
}
/*BLYNK_WRITE(V1)
{

Serial.print("V1 Slider value is: ");
Serial.println(int(param.asInt()));
}*/

void setup()
{
uint8_t mac[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x08 };
uint8_t ip[] = { 192, 168, 0, 63 };

Ethernet.begin(mac, ip);
Serial.begin(9600);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH);
Blynk.begin(auth);
timer.setInterval(1000L, sendSensor);
}

void loop()
{

Mb.Run();
Mb.R[3] = analogRead(A0);
Blynk.run();
timer.run();

}

You should read this:

Pete.

No!
I do not know how to set ip address for arduino. Because I need a fixed ip address to communicate with the PLC

So Google your question… it has nothing to do with Blynk. What you seem to have should work… if not, Google again :stuck_out_tongue_winking_eye:

PS, please do NOT double topic your issue… I have merged them both here.

I have a communication project between PLC (s7 1200), (Arduino + Ethernet shield) and Android.
The type of communication between PLC and ( Arduino + Ethernet shield) is Modbus TCP.
The type of communication between (Arduino + Ethernet shield) and Android is Blynk.
I do not know how to set ip and mac address for arduino. Because I need a fixed ip and mac address to communicate with the PLC s7 1200

You will find few examples here Blynk on GitHub

sorry

thanks! it’s very helpful

bạn ơi cho mình hỏi với ạ
code mình thế này :
#define BLYNK_PRINT Serial

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “df4a512426d44e7aaf8907d7428159b7”;

IPAddress server_ip (10, 0, 0, 10);

// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress arduino_ip (192, 168, 0, 10);
IPAddress dns_ip ( 8, 8, 8, 8);
IPAddress gateway_ip ( 192, 168, 1, 1);
IPAddress subnet_mask(255, 255, 255, 0);

#define W5100_CS 10
#define SDCARD_CS 4

void setup()
{
// Debug console
Serial.begin(9600);

pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

Blynk.begin(auth, server_ip, 8080, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
// Or like this:
//Blynk.begin(auth, “blynk-cloud.com”, 80, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);

}

void loop()
{
Blynk.run();
}

///////////////////////////////////////////////////////////
nạp vô rồi cái serial nó cứ connecting … conecting, thế này :
[0] Using static IP
[1300] IP:192.168.0.10
[1300]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.5.4 on Arduino Uno

[1417] Connecting to 10.0.0.10
[33660] Connecting to 10.0.0.10
[65671] Connecting to 10.0.0.10
[97681] Connecting to 10.0.0.10
[129691] Connecting to 10.0.0.10
[161700] Connecting to 10.0.0.10
[193711] Connecting to 10.0.0.10
///////////////////////////////////////////////////////////////
nó không kết nối được :frowning:

The third octets of your IP addresses are different, which means that unless you have some sort of bridging set-up on your network, the Ethernet shield won’t be able to send packets to the gateway because it’s on a different network.
I think you’ve used either the wrong IP address for the shield, or the IP address of your router (gateway) is incorrect.

This is also an odd IP address for a Blynk server. I don’t think it’s one of the Blynk cloud servers, so maybe it’s a local server hosted elsewhere that you’re using?
Are you able to ping 10.0.0.10 from your network?

Pete.

2 Likes

can i use :
Blynk.begin(auth, “blynk-cloud.com”, 80, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
instead of :
Blynk.begin(auth, server_ip, 8080, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac); ?
thanks!

@Tien_To Again… you already have your own topic about this issue… stay within it!
I moved your posts back here.

You also need to learn how to properly format your posted code here…

Blynk - FTFC