Cómo crear un servidor web para leer una tarjeta SD con nuestro PLC Ethernet Arduino

Servidor web Arduino para leer una tarjeta SD en el controlador PLC industrial Ethernet
9 de enero de 2019 por
Cómo crear un servidor web para leer una tarjeta SD con nuestro PLC Ethernet Arduino
Boot & Work Corp. S.L., Support Team

Introducción

En este ejemplo, podemos ver cómo crear un servidor web para leer una tarjeta SD en el PLC a través de una conexión Ethernet para la automatización industrial. Vamos a mostrar cómo crear un servidor que cuando hay una solicitud a través de un navegador, verás los directorios y los archivos de la tarjeta SD.

Sigue this post para asegurar una buena conexión de la tarjeta SD en el controlador lógico programable Ethernet Arduino.

Arduino sd card  Arduino sd card   Arduino sd card     

Requisitos

Controlador industrial Ethernet PLC

   Productos de la familia M-Duino

   Familia de prodcutos ESP32

ESP32 web server sd card
Librería Arduino SD

  Arduino SD Library

ESP32 web server sd card   Arduino automation

Software

Una vez que todo está conectado correctamente, el siguiente paso es realizar la configuración correcta del puerto Ethernet y crear el servidor:

/*
   Copyright (c) 2017 Boot&Work Corp., S.L. All rights reserved

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <SD.h> #include <Ethernet2.h> #define SD_SS_PIN 53 File root; // Enter a MAC address for your controller below. The MAC can be defined by yourself following the MAC standard structure rules. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; EthernetServer server(80); ///////////////////////////////////////////////////////////////////////////////// void setup() { Serial.begin(115200L); // Init Ethernet and TCP server Serial.println("Starting Ethernet ..."); Ethernet.begin(mac); server.begin(); // Init SD card Serial.println("Starting SD card ..."); if (!SD.begin(SD_SS_PIN)) { Serial.println("initialization failed!"); return; } Serial.print("IP address: "); Serial.println(Ethernet.localIP()); } /////////////////////////////////////////////////////////////////////////////// void loop() { EthernetClient client = server.available(); if (client) { char lastC = 0; while (client.connected()) { if (client.available()) { char c = client.read(); if ((c == '\n') && (lastC == '\n')) { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/plain"); client.println("Connection: close"); client.println(); client.println("SD card files:"); root = SD.open("/"); printDirectory(root, client); break; } if (c != '\r') { lastC = c; } } } delay(50); client.stop(); } } //////////////////////////////////////////////////////////////////////////////// void printDirectory(File dir, Stream &stream) { while (true) { File entry = dir.openNextFile(); if (!entry) { // no more files break; } stream.print(entry.name()); if (entry.isDirectory()) { stream.println("/"); } else { // files have sizes, directories do not stream.print(" ["); stream.print(entry.size(), DEC); stream.println("]"); } entry.close(); } }

Ver también

Conceptos básicos: tarjeta SD en Arduino PLC


 
 

Buscar en nuestro blog

Cómo crear un servidor web para leer una tarjeta SD con nuestro PLC Ethernet Arduino
Boot & Work Corp. S.L., Support Team 9 de enero de 2019
Compartir

¿Estás buscando tu Controlador Lógico Programable ideal?

Echa un vistazo a esta comparativa de producto de varios controladores industriales basados en Arduino.

Comparamos entradas, salidas, comunicaciones y otras especificaciones con las de los equipos de otras marcas destacadas.


Industrial PLC comparison >>>