strtok keeps on giving-- invalid conversion from 'char*' to 'char'

What gives, this is just like the C++ Referrence example for strtok. I keep on getting these blasted invalid conversion from 'char*' to 'char' [-fpermissive]. You can't use strtok for newlines?

Per strtok - C++ Reference, you will read:
char * strtok ( char * str, const char * delimiters );
So why is it expecting a char?!

  token = strtok(incomingPacket, "\n .");
      //switchCode2(token);
      while ( token != NULL ) {
        token = strtok(NULL,"\n .");
        //switchCode2(token);
      }

Post ALL the code and the complete error message.

Here is the whole code. Focus though on what’s above. Next are the errors. It should be simple to split a packet up line by line for Gods sakes.

#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

ESP8266WiFiMulti WiFiMulti;
WiFiUDP Udp;
char* rPacket, token, code;
const char* ssid = "JMR";
const char* password = "cr5";
int ix;

void setup() {

  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(ssid, password);

}

void loop() {
  char* incomingPacket; // wait for WiFi connection
const char newLine = ' ';
  if ((WiFiMulti.run() == WL_CONNECTED)) {

    HTTPClient http;

    USE_SERIAL.print("[HTTP] begin...\n");
    // configure traged server and url


    http.begin("http://matt:g0gs@192.168.1.71:15080/admin?profile=4");

    /*
      // or
      http.begin("http://192.168.1.12/test.html");
      http.setAuthorization("user", "password");

      // or
      http.begin("http://192.168.1.12/test.html");
      http.setAuthorization("dXNlcjpwYXN3b3Jk");
    */


    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();
  }
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;
      }
     
      Serial.println(incomingPacket);

      //Packet Parse
      //Split packet into codes
      token = strtok(incomingPacket, '/n');
      //switchCode2(token);
      while ( token != NULL ) {
        token = strtok(NULL,'/n');
        //switchCode2(token);
      }
      if (millis() - delayMS > 1000) Serial.println(9102);
    }
  }
}
  delay(100);
}
C:\Users\matt\AppData\Local\Temp\arduino_modified_sketch_129531\Authorization.ino: In function 'void loop()':

Authorization:96: error: invalid conversion from 'char' to 'const char*' [-fpermissive]

       token = strtok(incomingPacket, newLine);

                                             ^

In file included from C:\Users\matt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include/string.h:10:0,

                 from C:\Users\matt\AppData\Local\Temp\arduino_modified_sketch_129531\Authorization.ino:1:

C:\Users\matt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include/string.h:42:15: error:   initializing argument 2 of 'char* strtok(char*, const char*)' [-fpermissive]

 char  *_EXFUN(strtok,(char *__restrict, const char *__restrict));

               ^

C:\Users\matt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include/_ansi.h:65:30: note: in definition of macro '_EXFUN'

 #define _EXFUN(name, proto)  name proto

                              ^

Authorization:96: error: invalid conversion from 'char*' to 'char' [-fpermissive]

       token = strtok(incomingPacket, newLine);

                                             ^

C:\Users\matt\AppData\Local\Temp\arduino_modified_sketch_129531\Authorization.ino:98:24: warning: NULL used in arithmetic [-Wpointer-arith]

       while ( token != NULL ) {

                        ^

Authorization:99: error: invalid conversion from 'char' to 'const char*' [-fpermissive]

         token = strtok(NULL,newLine);

                                    ^

In file included from C:\Users\matt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include/string.h:10:0,

                 from C:\Users\matt\AppData\Local\Temp\arduino_modified_sketch_129531\Authorization.ino:1:

C:\Users\matt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include/string.h:42:15: error:   initializing argument 2 of 'char* strtok(char*, const char*)' [-fpermissive]

 char  *_EXFUN(strtok,(char *__restrict, const char *__restrict));

               ^

C:\Users\matt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2/tools/sdk/libc/xtensa-lx106-elf/include/_ansi.h:65:30: note: in definition of macro '_EXFUN'

 #define _EXFUN(name, proto)  name proto

                              ^

Authorization:99: error: invalid conversion from 'char*' to 'char' [-fpermissive]

         token = strtok(NULL,newLine);

                                    ^


C:\Users\matt\AppData\Local\Temp\arduino_modified_sketch_129531\Authorization.ino: At global scope:

Authorization:105: error: expected declaration before '}' token

 }

 ^

exit status 1
invalid conversion from 'char' to 'const char*' [-fpermissive]

Your first post clearly stated that the second parameter to the function must be a 'const char *':

char * strtok ( char * str, const char * delimiters );

Why are you trying to pass it a char?

token = strtok(incomingPacket, '/n');
token = strtok(NULL,'/n');

Also, the function returns a ‘char *’. You’re trying to assign it to ‘token’ which is a ‘char’:

char* rPacket, token, code;

Edit:
In the line above, the ‘*’ only applies to ‘rPacket’.

Shouldn't this

token = strtok(incomingPacket, '/n');

be

token = strtok(incomingPacket, "\n");

As well as the incorrect slash I believe you need double quotes

...R

for (uint8_t t = 4; t > 0Oops

gfvalvo:
Also, the function returns a 'char *'. You're trying to assign it to 'token' which is a 'char':

char* rPacket, token, code;

Edit:
In the line above, the '*' only applies to 'rPacket'.

Winner winner. This is the jam you get yourself into trying to jam multiple things on one line. If you write them out it takes minimal effort, no resources, and saves you from this type of thing.

gfvalvo:
In the line above, the '*' only applies to 'rPacket'.

Thanks. That's useful to know. I always put things on separate lines myself.

...R

Its crashing anyhow, exception (29). Here is the new sketch, then decode of stack dump. I removed all of WiFiMulti which I thought was the culprit. My ESP8266HTTPClient.h is up to date according to lib mgr.

#include <string.h>
#include <stdio.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ESP8266HTTPClient.h>

WiFiUDP Udp;
HTTPClient http;

char* rPacket;
char* token;
char* code;
const char* ssid = "JMR";
const char* password = "poop";
int ix;
long delayMS;
unsigned int localUdpPort = 8888;  // local port to listen on
char incomingPacket[255];  // buffer for incoming packets

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

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

  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);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" connected");

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

void loop() {
  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());
    char* incomingPacket;
    int len = Udp.read(incomingPacket, 255);
    if (len > 0)
    {
      incomingPacket[len] = 0;
    }

    Serial.println(incomingPacket);

    //Packet Parse
    //Split packet into codes
    //EXAMPLE

    char * pch;
    //printf ("Splitting string \"%s\" into tokens:\n", incomingPacket);
    pch = strtok (incomingPacket, "\n");
    switchCode(pch);
    while (pch != NULL)
    {
      printf ("%s\n", pch);
      pch = strtok (NULL, "\n");
      switchCode(pch);
    }
    http.end();
  }
  if (millis() - delayMS > 1000) Serial.println(9102);
  delayMS = millis();

  delay(1);
}
void switchCode(char * code) {
  Serial.println(code);
  if (strcmp(code, "7004")  == 0) {
    http.begin("http://poop@192.168.1.71:15080/admin?profile=4");
  }
}
Decoding 9 results
0x40104ab2: wdt_feed at ?? line ?
0x40104b6e: ets_timer_setfn at ?? line ?
0x40104d40: ets_timer_arm_new at ?? line ?
0x40203bc0: esp_yield at C:\Users\matt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/core_esp8266_main.cpp line 91
0x402014f2: delay at C:\Users\matt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/core_esp8266_wiring.c line 54
0x402014e7: delay at C:\Users\matt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/core_esp8266_wiring.c line 51
0x40202690: loop at C:\Users\matt\Documents\Arduino\node9-4/node9-4.ino line 52
0x40203c4c: loop_wrapper at C:\Users\matt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/core_esp8266_main.cpp line 125
0x40100739: cont_wrapper at C:\Users\matt\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266/cont.S line 81

I think the thing is crashing on the Udp.read. I've been working on it for hours. Can't you run a http client and receive UDP packets?

EDIT: It does seem to be the Udp.read. I commented it out and now it runs, but not really.

UDP seems totally incompatible with with ESP8266httpclient.

Is there another http client library that works on the ESP12E? Or UDP?

mattlogue:
Its crashing anyhow, exception (29).

It may be crashing "anyhow", but that's a different problem. Before is wasn't compiling because of the errors noted in your code. Now it appears to be compiling. So, I'd say this thread (per its title) is [SOLVED].