Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

sending http through esp

Status
Not open for further replies.

Dr_Doggy

Well-Known Member
reposting since i made some progress here, but still alot of problems ....

my main loop really only does one thing but its imperative that the thing happens at least every second
Code:
void loop()
{    //delay(1000);
    runPumps();
    checkWifi();   
    checkSerial();   
}

for check serial it looks for serial or http input, then spits out accordingly .. when it thinks it is at response it puts it in to the atResponse variable however due to packet size limitations i had to break it down to several steps ... mostly waiting for ATresponses

Code:
void checkWifi()
{  
    switch (wifiStatus)
    {
// CASES 1-41 .... steps to pair the esp after fresh boot ............
// CASES 100-131  ..... steps to send a basic http404page
..................................... similar to a state machine .......................................
    case 1:    delay(500); Serial1.println("AT"); wifiStatus = 11; break;
    case 11:delay(500); if (strstr(atResponse, "OK") != 0){ clearWifiBuffer(); tsClear(atResponse); wifiStatus = 2;  } break;

    case 2: delay(500); Serial1.println("AT+CIFSR");  wifiStatus = 21;  break;
    case 21:delay(500); if (strstr(atResponse, "+CIFSR:STAIP,\"192.168.100.218\"") != 0){ clearWifiBuffer(); tsClear(atResponse); wifiStatus = 3;  } break;

    case 3: delay(500);  wifiStatus = 31; timeout = timeoutByte; tsClear(atResponse); Serial1.println("AT+CIPMUX=1"); break;
    case 31:delay(500); if ((strstr(atResponse, "K\r") != 0) || (strstr(atResponse, "ink is builded") != 0)){ clearWifiBuffer(); tsClear(atResponse); wifiStatus = 4; }if (!timeout--){ tsClear(atResponse); timeout = timeoutByte; wifiStatus = 3; } break;

    case 4: delay(500); Serial1.println("AT+CIPSERVER=1,80");  wifiStatus = 41;; break;
    case 41:delay(500); if ((strstr(atResponse, "OK") != 0) || (strstr(atResponse, "no change") != 0)){ clearWifiBuffer(); tsClear(atResponse); wifiStatus = 255; Serial.print("wifi PAIRED!"); } break;

       


    case 100: delay(500); atDataSend(doctype1);  wifiStatus = 101; break;
    case 101:delay(500); if ((strstr(atResponse, "SENT") != 0) || (strstr(atResponse, "SENT") != 0)){ clearWifiBuffer(); tsClear(atResponse); wifiStatus = 110; Serial.println("11"); } break;
       
    case 110: delay(500); atDataSend(head);  wifiStatus = 111; break;
    case 111:delay(500); if ((strstr(atResponse, "SENT") != 0) || (strstr(atResponse, "SENT") != 0)){ clearWifiBuffer(); tsClear(atResponse); wifiStatus = 120; Serial.println("22"); } break;

    case 120: delay(500); atDataSend(body400);  wifiStatus = 121; break;
    case 121:delay(500); if ((strstr(atResponse, "SENT") != 0) || (strstr(atResponse, "SENT") != 0)){ clearWifiBuffer(); tsClear(atResponse); wifiStatus = 130;  Serial.println("33"); } break;

    case 130: delay(500); atDataSend(bodyTerminator);  wifiStatus = 131; break;
    case 131:delay(500); if ((strstr(atResponse, "SENT") != 0) || (strstr(atResponse, "SENT") != 0)){ clearWifiBuffer(); tsClear(atResponse); wifiStatus = 255; Serial.println("44"); } break;

    case 255:break;

but now that i use this method i can no longer refer the connection number on the outgoing packet which was found on the original incoming packet without this CON no it creates the potential to have packets confused with other incoming packets from a different client... because with this method the variables and buffers are global ... unlike before they were called with subroutines within subroutines and the connection number got passed down??
also i cannot start the server when AT+MUX=0; , so i need to leave multiple connections on.

and really the problem is mostly that data gets lost with too much cross chatter between the modules so i need to wait for response before proceeding with next instruction ... in case it returns "busy"

what is the best way to handle all this chatter?/
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top