Browse our Blog. You will find multiple applications, solutions, code examples. Navigate using the tag cloud or search using specific criteria

Http requests to a server using an Arduino based PLC

Working with external servers using Industrial Arduino Solutions


In this post we will show you how to perform HTTP requests with the POST method to send information to an external server.

The information is received from analog data of a potentiometer filtered by software. 
If you want to know more about analog data filtering do not hesitate to follow this post!


Ethernet PLC or 20 I/Os PLC:
Ethernet PLC >>     20 I/Os PLC >>

ArduinoHTTPClient library:
Download ArduinoHTTPClient library on Github >>

Industrial Shields Power supply:
Industrial Shields Accessories >>

Industrial Shields boards:
Install Industrial Shields boards >>

To know the part related to the connection of the potentiometer , the Analog data filtering and also the SD card datalog, follow this blog post.

The Ethernet PLC will act as a client making write requests to the server to send the analog data received periodically. This will be connected via Ethernet to a Router with access to the server where the received data is written.

So that, at the Hardware level we will only require an ethernet connection between the Arduino-based PLC and the server.


This sketch creates a client in our PLC based on Arduino responsible for making POST requests to the URL path composed of server IP + "/ analog-value":

The values that we will show in the server will be the filtered analog results received from a potentiometer connected to the Arduino based PLC to be able to test the global operation of this test. 

The post requests that the server waits follows this structure: {"value": data}.


 Copyright (c) 2018 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


   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 <>.


#include <ArduinoHttpClient.h>
#include <Ethernet.h>
#include <SD.h>
#include <Filter.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 
IPAddress server(192,168,1,209); 

int port = 1880;

Sd2Card card;
SdVolume volume;

AnalogFilter<5, 2> aFilter;

EthernetClient ether;
HttpClient client = HttpClient(ether,server,port);
String response;

void setup() {
  // Ethernet.begin(mac,ip,dnsServer,gateway,subnet);
  Serial.print("IP: ");
  if (!SD.begin(53)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  Serial.println("card initialized.");

void loop() {
  int data = analogRead(I0_12);
   int filtered = aFilter.update(data);
  static uint32_t lastPrint = millis();
  if (millis() - lastPrint > 3000) {
    lastPrint = millis();
    String postData = "{\"value\":" + String(filtered) + "}";

    client.sendHeader("Content-Type", "application/json");
    client.sendHeader("Content-Length", postData.length());

    int statusCode = client.responseStatusCode();

    Serial.println(statusCode);   //Prints the HTTP status response - 200 if OK
    Serial.println("Data to the Server");
    Serial.println("Wait one seconds");

void logToSd(int value){
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile ="datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");

HTTP requests to a server using an Arduino Based PLC 


Do you want more information?

Open Source technology allows you to develop your installations.

Just fill the form and we will contact you as soon as we can.