****SOLVED****** UDP and HTTP client don't mix? http not delcared.

SOLVED**
Background: HTTPclient http; was in a loop. It had to be global.

I wanted to have a program listen for UDP packet of a certain code and then GET a webpage (to sound an alarm). I pieced together almost everything from NodeMCUs “Authorization” sketch into my UDP sketch. It says ‘http’ is not declared. It’s not my includes, I ruled those out already.

What is wrong?

#include <string.h>
#include <stdio.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#define USE_SERIAL Serial

char* rPacket;
const char* ssid = "JMR";
const char* password = "";
int ix;

ESP8266WiFiMulti WiFiMulti;
WiFiUDP Udp;
long delayMS;
unsigned int localUdpPort = 8888;  // local port to listen on
char incomingPacket[255];  // buffer for incoming packets
char  replyPacket[] = "Hi there! Got the message :-)";  // a reply string to send back
const char newLine[2] = "\n";

void setup()
{
  Serial.begin(115200);
  Serial.println();

  Serial.printf("Connecting to %s ", ssid);

  USE_SERIAL.begin(115200);
  // USE_SERIAL.setDebugOutput(true);

  USE_SERIAL.println();
  USE_SERIAL.println();
  USE_SERIAL.println();

  for (uint8_t t = 4; t > 0; t--) {
    USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
    USE_SERIAL.flush();
    delay(1000);
  }

  WiFi.mode(WIFI_STA);
  WiFiMulti.addAP("JMR", "crystal2965");

  IPAddress ip(192, 168, 1, 139);
  IPAddress gw(192, 168, 1, 254);
  IPAddress dns(192, 168, 1, 254);
  IPAddress sn(255, 255, 255, 0);
  WiFi.config(ip, gw, sn, dns);

  Udp.begin(localUdpPort);
  Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);
}

void switchCode2(char* code) {
  int codei = atoi(code);
  switch (codei) {
    case 7004: openWeb(); //magnet break
  }
  rPacket = "R";
  rPacket = strcat(rPacket, code);
  // send back a reply, to the IP address and port we got the packet from
  Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
  Udp.write(rPacket);
  Udp.endPacket();

}
void loop()
{
  char* pack;
  char* token;

  if ((WiFiMulti.run() == WL_CONNECTED)) {
    HTTPClient http;
    USE_SERIAL.print("[HTTP] begin...\n");


    int packetSize = Udp.parsePacket();
    if (packetSize)
    {
      // receive incoming UDP packets
      //Serial.println("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
      int len = Udp.read(incomingPacket, 255);
      if (len > 0)
      {
        incomingPacket[len] = 0;
      }
      pack = incomingPacket;
      Serial.println(incomingPacket);

      //Packet Parse
      //Split packet into codes
      token = strtok(pack, newLine);
      switchCode2(token);
      while ( token != NULL ) {
        token = strtok(NULL, newLine);
        switchCode2(token);
      }
      if (millis() - delayMS > 1000) Serial.println(9102);
    }
  }
}

void openWeb() {
  USE_SERIAL.print("[HTTP] begin...\n");
  // configure traged server and url
  http.begin("http://mat00gs@192.168.1.71:15080/admin?profile=6");
  USE_SERIAL.print("[HTTP] GET...\n");
  // start connection and send HTTP header
  int httpCode = http.GET();

  // httpCode will be negative on error
  if (httpCode > 0) {
    // HTTP header has been send and Server response header has been handled
    USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

    // file found at server
    if (httpCode == HTTP_CODE_OK) {
      String payload = http.getString();
      USE_SERIAL.println(payload);
    }
  } else {
    USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
  }

  http.end();
}

Well, where is http declared?

In the basic example for the client I see this:

   HTTPClient http;

    Serial.print("[HTTP] begin...\n");
    if (http.begin(client, "http://jigsaw.w3.org/HTTP/connection.html")) {  // HTTP

I'm not sure. I copied it from an example that had all of the same lines.

Make it global. You've declared it locally in loop and you're trying to use it in OpenWeb.

Thanks WildBill, now it compiles.

Now it isn’t running. Throws an execption. Thing is I don’t know if the “Authorization” sketch would crash too. And ESP exception decoder isn’t working! I’m gonna go to bed. Does anybody know a SIMPLE authorization HTTP sketch, one that doesn’t care if you are connected via wifi or ethernet? Because I think the issue is I have conflicts in wifi commands.

While it's solved but it does appear that UDP will throw an exception when ran with HttpClient. I have to code the HTTPclient myself from a TCP client.