invalid conversion from 'char' to 'const char*' [-fpermissive] problem
code: [select]
#include <esp_adafruit_ssd1306.h>
#include <avr/pgmspace.h>
#include <softwareserial.h>
#include <wire.h>
#include <adafruit_gfx.h>
#define oled_reset 4
adafruit_ssd1306 display(oled_reset);
#if (ssd1306_lcdheight != 64)
#error("height incorrect, please fix adafruit_ssd1306.h!");
#endif
#define debug true
softwareserial esp8266(2, 3); // make rx arduino line pin 2, make tx arduino line pin 3.
// means need connect tx line esp arduino's pin 2
// , rx line esp arduino's pin 3
void setup()
{
display.begin(ssd1306_switchcapvcc, 0x3c); // initialize i2c addr 0x3d (for 128x64)
display.cleardisplay();
delay(5000);
serial.begin(9600);
esp8266.begin(9600); // esp's baud rate might different
pinmode(11, output);
digitalwrite(11, low);
pinmode(12, output);
digitalwrite(12, low);
pinmode(13, output);
digitalwrite(13, low);
pinmode(10, output);
digitalwrite(10, low);
char atreset[11] progmem = "at+rst\r\n";
char atcwmode[17] progmem = "at+cwmode=1\r\n";
char atcwjap[37] progmem = "at+cwjap=\"rajahome\",\"rama2869\"\r\n";
char atcifsr[13] progmem = "at+cifsr\r\n";
char atcipmux[17] progmem = "at+cipmux=1\r\n";
char atcipserver[22] progmem = "at+cipserver=1,80\r\n";
sendcommand(atreset, 2000, debug); // reset module
sendcommand(atcwmode, 2000, debug); // configure access point
sendcommand(atcwjap, 3000, debug);
delay(10000);
sendcommand(atcifsr, 3000, debug); // ip address
sendcommand(atcipmux, 1000, debug); // configure multiple connections
sendcommand(atcipserver, 1000, debug); // turn on server on port 80
serial.println(f("server ready"));
}
void loop()
{
if (esp8266.available()) // check if esp sending message
{
if (esp8266.find("+ipd,"))
{
delay(1000); // wait serial buffer fill (read serial data)
// connection id can disconnect
int connectionid = esp8266.read() - 48; // subtract 48 because read() function returns
// ascii decimal value , 0 (the first decimal number) starts @ 48
esp8266.find("pin="); // advance cursor "pin="
int pinnumber = (esp8266.read() - 48); // first number i.e. if pin 13 1st number 1
int secondnumber = (esp8266.read() - 48);
if (secondnumber >= 0 && secondnumber <= 9)
{
pinnumber *= 10;
pinnumber += secondnumber; // second number, i.e. if pin number 13 2nd number 3, add first number
}
digitalwrite(pinnumber, !digitalread(pinnumber)); // toggle pin
// build string send device requesting pin toggle
char content[15] progmem="pin ";
char pin[1] progmem={48};
strcat(content,pin);
strcat(content,"is");
if (digitalread(pinnumber))
{
strcat(content,"on");
}
else
{
strcat(content,"off");
}
sendhttpresponse(connectionid, content);
char closecommand[16] progmem = "at+cipclose=";
// make close command
char cid[2] progmem = {48}; //ascii value of 0 48
strcat(closecommand, cid); //append connectionid
strcat(closecommand, "\r\n");
sendcommand(closecommand, 1000, debug); // close connection
}
}
}
/*
name: senddata
description: function used send data esp8266.
params: command - data/command send; timeout - time wait response; debug - print serial window?(true = yes, false = no)
returns: response esp8266 (if there reponse)
*/
char senddata(char command[], const int timeout, boolean debug)
{
char response[100] progmem = "";
int datasize = strlen(command);
char data[datasize] progmem;
//command.tochararray(data, datasize);
esp8266.write(data, datasize); // send read character esp8266
if (debug)
{
serial.println("\r\n====== http response arduino ======");
serial.write(data, datasize);
serial.println("\r\n========================================");
}
long int time = millis();
while ( (time + timeout) > millis())
{
while (esp8266.available())
{
// esp has data display output serial window
char c progmem= esp8266.read(); // read next character.
strcat(response,c);
}
}
if (debug)
{
serial.print(response);
}
return response;
}
/*
name: sendhttpresponse
description: function sends http 200, html utf-8 response
*/
void sendhttpresponse(int connectionid, char content[])
{
contentlen=strlen(content);
// build http response
char httpresponse[100] progmem;
char httpheader[100] progmem;
// http header
strcat(httpheader,"http/1.1 200 ok\r\ncontent-type: text/html; charset=utf-8\r\n");
strcat(httpheader,"content-length: ");
strcat(httpheader,contentlen);
strcat(httpheader,"\r\n");
strcat(httpheader,"connection: close\r\n\r\n");
httpresponse = strcat(httpheader,content," "); // there bug in code: last character of "content" not sent, cheated adding space
sendcipdata(connectionid, httpresponse);
}
/*
name: sendcipdata
description: sends cipsend=<connectionid>,<data> command
*/
void sendcipdata(int connectionid, char data[])
{
char cipsend[40] progmem = "at+cipsend=";
char cid[2]progmem = {48};
datalen=strlen(data)
strcat(cipsend, cid);
strcat(cipsend, ",");
strcat(cipsend,datalen));
strcat(cipsend, "\r\n");
sendcommand(cipsend, 1000, debug);
senddata(data, 1000, debug);
}
/*
name: sendcommand
description: function used send data esp8266.
params: command - data/command send; timeout - time wait response; debug - print serial window?(true = yes, false = no)
returns: response esp8266 (if there reponse)
*/
char sendcommand(char command[], const int timeout, boolean debug)
{
char response[50] progmem = "";
esp8266.print(command); // send read character esp8266
long int time = millis();
while ( (time + timeout) > millis())
{
while (esp8266.available())
{
// esp has data display output serial window
char c = esp8266.read(); // read next character.
response += c;
}
}
if (debug)
{
delay(2000);
// text display tests
display.settextsize(1);
display.settextcolor(white);
display.setcursor(0, 0);
display.print(response);
display.display();
// clear buffer.
display.cleardisplay();;
}
return response;
}
and error
c:\users\user\documents\arduino\espcontrll\espcontrll.ino: in function 'char senddata(char*, int, boolean)':
espcontrll:144: error: invalid conversion 'char' 'const char*' [-fpermissive]
i optimized code something not working had used c-string instead of string class to save ram usage still not going right can me these
code: [select]
char response[50] progmem = "";
good luck adding that.
Arduino Forum > Using Arduino > Project Guidance > invalid conversion from 'char' to 'const char*' [-fpermissive] problem
arduino
Comments
Post a Comment