Post topics, source code that relate to the Arduino Platform

User avatar
By 1simone0
#70123 Hello everyone! I'm sorry for my bad english but I'll try to explain my trouble with an esp8266 developed by dfrobot, this is the store link: https://www.dfrobot.com/product-1279.html.
I'm trying to send datas from my Arduino Mega 2560 to a web server.
Actually I'm be able to make a GET request to send a value to a php file in the web server but I Would like to send several datas using just one GET request. I found on google a way (using the simbol "&" to send 2 values to 2 differents variables in the SAME PHP FILE but I cannot find something about to send several values to different php file wich is my goal!
Is it possible? if not, is there a way to do it (maybe with more GET request) with no close and re-open the connection to the server every value sent? because this take some precoius second..... :roll:
I'm using the arduino library ESP8266.h
and this is my sketch:

Code: Select all#include "ESP8266.h"
#define SSID        "mySSID" //Gnigni'_WIFI  Eugeni Wi_Fi
#define PASSWORD    "myPASSWORD"  //fleugeniwifi
#define HOST_NAME   "mySERVER"
#define HOST_PORT   (80)

ESP8266 wifi(Serial1);

void setup(void)
{
    Serial.begin(115200);
    Serial.print("setup begin\r\n");

    Serial.print("FW Version:");
    Serial.println(wifi.getVersion().c_str());

    if (wifi.setOprToStationSoftAP()) {
        Serial.print("to station + softap ok\r\n");
    } else {
        Serial.print("to station + softap err\r\n");
    }

    if (wifi.joinAP(SSID, PASSWORD)) {
        Serial.print("Join AP success\r\n");

        Serial.print("IP:");
        Serial.println( wifi.getLocalIP().c_str());       
    } else {
        Serial.print("Join AP failure\r\n");
    }
   
    if (wifi.disableMUX()) {
        Serial.print("single ok\r\n");
    } else {
        Serial.print("single err\r\n");
    }
   
    Serial.print("setup end\r\n");
    delay(2000);
}
 
void loop(void)
{
    uint8_t buffer[1024] = {0};

    if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
        Serial.print("create tcp ok\r\n");
    } else {
        Serial.print("create tcp err\r\n");
    }
//the following line is my GET request
    char *hello = "GET /biobot/write1.php?value=22HTTP/1.1\r\nHost: mySERVER\r\nConnection: close\r\n\r\n";
   
    wifi.send((const uint8_t*)hello, strlen(hello));

    uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
    if (len > 0) {
        Serial.print("Received:[");
        for(uint32_t i = 0; i < len; i++) {
            Serial.print((char)buffer[i]);
        }
        Serial.print("]\r\n");
    }

    if (wifi.releaseTCP()) {
        Serial.print("release tcp ok\r\n");
    } else {
        Serial.print("release tcp err\r\n");
    }
    delay(1000);
   
    if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
        Serial.print("create tcp ok\r\n");
    } else {
        Serial.print("create tcp err\r\n");
    }

    char *hello2 = "GET /biobot/write2.php?value=44 HTTP/1.1\r\nHost: peretti.ddns.net\r\nConnection: close\r\n\r\n"; // SE SI VUOLE FARE UNA POST PROVARE A MODIFICARE QUESTA RIGA
   
    wifi.send((const uint8_t*)hello2, strlen(hello2));

    uint32_t len2 = wifi.recv(buffer, sizeof(buffer), 10000);
    if (len > 0) {
        Serial.print("Received:[");
        for(uint32_t i = 0; i < len; i++) {
            Serial.print((char)buffer[i]);
        }
        Serial.print("]\r\n");
    }

    if (wifi.releaseTCP()) {
        Serial.print("release tcp ok\r\n");
    } else {
        Serial.print("release tcp err\r\n");
    }
    delay(1000);
}

thanks to who will help me!!! :D
and if you have some more suggestions about this topic you are welcome to teach me ;)
User avatar
By martinayotte
#70153 No, you can not do several GET to diffrent URL using a single GET.
But you can have your PHP server acting as a proxy, which mean that it would received a single GET request, and the PHP Server would then act as client re-dispatching severals GET requests to other servers.