plc.myforum.ro Forum Index plc.myforum.ro
PLCs users www.plc.myforum.ro!
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to connect esp8266 to plc s7-1200 ?

 
Post new topic   Reply to topic    plc.myforum.ro Forum Index -> Siemens Hardware & Software
View previous topic :: View next topic  
Author Message
nhllong123
Junior
Junior


Joined: 15 Apr 2018
Posts: 1

PostPosted: 28/02/2019 11:41    Post subject: How to connect esp8266 to plc s7-1200 ? Reply with quote

Hello. I'm Long, i have a project is esp8266 get the data from plc s7-1200 and then put them to webserver. I tried to connect between esp and plc but it's not works. By the way i use settimino library and reference from the website/blog: https://www.instructables.com/id/ARDUINO-HACK-PLC-SIEMENS-THROUGH-LANWIFI-INDUSTRIA/ .
Any ideas?
Help me.
Thanks everyone.
All my project in here: https://drive.google.com/drive/folders/1YL_OqZp5JZ5akcdqszr7pQOXqKywO5ke?usp=sharing
Back to top
View user's profile Send private message
Rewhy22
Junior
Junior


Joined: 11 Jan 2019
Posts: 2

PostPosted: 17/03/2019 06:28    Post subject: Reply with quote

https://sourceforge.net/p/snap7/discussion/general/thread/e6bb6b66/?limit=25

Code:
DB Get Demo

 Created 19 Nov 2013
 by Davide Nardella
 
------------------------------------------------------------------------
This demo shows how to upload an entire DB from the PLC without
knowing its size in advance.
A DB1 with not more than 1024 byte into the PLC is needed.

- During the loop, try to disconnect the ethernet cable.
  The system will report the error and will reconnect automatically
  when you re-plug the cable.
- For safety, this demo *doesn't write* data into the PLC, try
  yourself to change ReadArea with WriteArea.
- This demo uses ConnectTo() with Rack=0 and Slot=2 (S7300)
  - If you want to connect to S71200/S71500 change them to Rack=0, Slot=0.
  - If you want to connect to S7400 see your hardware configuration.
  - If you want to work with a LOGO 0BA7 or S7200 please refer to the
    documentation and change
    Client.ConnectTo(<IP>, <Rack>, <Slot>);
    with the couple
    Client.SetConnectionParams(<IP>, <LocalTSAP>, <Remote>);
    Client.Connect();
----------------------------------------------------------------------*/
#include <SPI>
#include <Ethernet>
#include "Settimino.h"

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x0F, 0x08, 0xE11 };
 
IPAddress Local(192,168,0,70); // Local Address
IPAddress PLC(192,168,0,71);   // PLC Address

byte Buffer[512];

S7Client Client;
unsigned long Elapsed; // To calc the execution time
//----------------------------------------------------------------------
// Setup : Init Ethernet and Serial port
//----------------------------------------------------------------------
void setup() {
    // Open serial communications and wait for port to open:
    Serial.begin(9600);
     while (!Serial) {
      ; // wait for serial port to connect. Needed for Leonardo only
    }
    // Start the Ethernet Library
    Ethernet.begin(mac, Local);
    // Setup Time, someone said me to leave 2000 because some
    // rubbish compatible boards are a bit deaf.
    delay(2000);
    Serial.println(Ethernet.localIP());
}
//----------------------------------------------------------------------
// Connects to the PLC
//----------------------------------------------------------------------
bool Connect()
{
    int Result=Client.ConnectTo(PLC,
                                  0,  // Rack (see the doc.)
                                  2); // Slot (see the doc.)
    Serial.print("Connecting to ");Serial.println(PLC); 
    if (Result==0)
    {
      Serial.print("Connected ! PDU Length = ");Serial.println(Client.GetPDULength());
    }
    else
      Serial.println("Connection error");
    return Result==0;
}
//----------------------------------------------------------------------
// Dumps a buffer (a very rough routine)
//----------------------------------------------------------------------
void Dump(void *Buffer, int Length)
{
  int i, cnt=0;
  pbyte buf;
 
  if (Buffer!=NULL)
    buf = pbyte(Buffer);
  else 
    buf = pbyte(&PDU.DATA[0]);

  Serial.print("[ Dumping ");Serial.print(Length);
  Serial.println(" bytes ]==========================");
  for (i=0; i<Length; i++)
  {
    cnt++;
    if (buf[i]<0x10)
      Serial.print("0");
    Serial.print(buf[i], HEX);
    Serial.print(" ");
    if (cnt==16)
    {
      cnt=0;
      Serial.println();
    }
  } 
  Serial.println("===============================================");
}
//----------------------------------------------------------------------
// Prints the Error number
//----------------------------------------------------------------------
void CheckError(int ErrNo)
{
  Serial.print("Error No. 0x");
  Serial.println(ErrNo, HEX);
 
  // Checks if it's a Severe Error => we need to disconnect
  if (ErrNo & 0x00FF)
  {
    Serial.println("SEVERE ERROR, disconnecting.");
    Client.Disconnect();
  }
}
//----------------------------------------------------------------------
// Profiling routines
//----------------------------------------------------------------------
void MarkTime()
{
  Elapsed=millis();
}
//----------------------------------------------------------------------
void ShowTime()
{
  // Calcs the time
  Elapsed=millis()-Elapsed;
  Serial.print("Job time (ms) : ");
  Serial.println(Elapsed);   
}
//----------------------------------------------------------------------
// Main Loop
//----------------------------------------------------------------------
void loop()
{
 
  uint16_t Size;
  int Result;
  Size = sizeof(Buffer);
 
  // Connection
  while (!Client.Connected)
  {
    if (!Connect())
      delay(500);
  }
 
  Serial.println("Uploading DB2");
  // Get the current tick
  MarkTime();
  Result=Client.DBGet(2,       // DB Number = 1
                      &Buffer, // Our Buffer
                      &Size);  // In input contains our buffer size
                               // As output contains the data read
  if (Result==0)
  {
    ShowTime();
    Dump(&Buffer, Size);
  }
  else
    CheckError(Result);
   
  delay(500); 
}
Back to top
View user's profile Send private message
LOHNTOZ11
Junior
Junior


Joined: 28 Apr 2020
Posts: 2

PostPosted: 08/01/2021 15:44    Post subject: Re: How to connect esp8266 to plc s7-1200 ? Reply with quote

nhllong123 wrote:
Hello. I'm Long, i have a project is esp8266 get the data from plc s7-1200 and then put them to webserver. I tried to connect between esp and plc but it's not works. By the way i use settimino library and reference from the website/blog: https://www.instructables.com/id/ARDUINO-HACK-PLC-SIEMENS-THROUGH-LANWIFI-INDUSTRIA/ .
Any ideas?
Help me.
Thanks everyone.
All my project in here: https://drive.google.com/drive/folders/1YL_OqZp5JZ5akcdqszr7pQOXqKywO5ke?usp=sharing


Siemens S7-1200 PLC to Arduino
https://www.youtube.com/watch?v=SFH__4E0CwM
Siemens S7 1200 Modbus TCP/IP Communication with Arduino
https://www.youtube.com/watch?v=c2T2lAMDWGs
Arduino - Read Data from S7 Siemens PLC
https://www.youtube.com/watch?v=pG96O0b76_c
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    plc.myforum.ro Forum Index -> Siemens Hardware & Software All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Fa-ti si tu propriul forum GRATUIT, pe www.myforum.ro