Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By xtal
#37824 I have the following strings I need to parse but have not been unable to achieve some working code...
K1 => K 1 byte ,byte
K2 => K 2 byte, byte
K3 => K 3 byte, byte
K4xxx => K 4 xxx = 0-255 byte, byte, word or byte
K5xxx => K 4 xxx = 0-255 byte, byte, word or byte
ZAByyyyy Z A = 1-5 B=0-9 yyyyy = 0-65535 byte, byte, byte, word

I just cannot save 1 char from string using string.substring(x,y) I get errors trying char, byte etc...
have not tried saving the 0-255 or 0-65535 values yet....

Arduino: 1.6.5 (Windows 7), Board: "Generic ESP8266 Module, Serial, 80 MHz, 40MHz, DIO, 115200, 512K (64K SPIFFS), ck"

wifi-web-servad.ino.ino: In function 'void loop()':
wifi-web-servad.ino:156: error: cannot convert 'String' to 'char' in assignment
wifi-web-servad.ino:157: error: cannot convert 'String' to 'char' in assignment
cannot convert 'String' to 'char' in assignment




Code: Select all  else if (PayLD.indexOf("cx=") != -1)              // insure cx= exist this PayLoad
      { int s_mit = (PayLD.indexOf("cx="));           // find cx= start position       
        String submit = PayLD.substring(s_mit+3);     // save string
        submit.toUpperCase();                         // make upper case
        cmx = "cx=" + submit;                         // display data 

char Ax = 0;
char Axx = 0;
                 
        Ax = submit.substring(0,1);               // K=     Z=
        Axx = submit.substring(1,2);         
        if (Ax == 75)                                 // found k/75 in position 0 = good
          {         
            Serial.println("K-");
            Serial.println(submit);
             cmx = "cx="+ submit;   } 
                     
        else if (Ax == 90)                            // found z/90 in position 0 = good       
           {Serial.println("Z-");
            Serial.println(submit);
             cmx = "cx="+ submit;   }               
        else
           { Serial.println("!K/Z "+ submit); }             
      }
User avatar
By martinayotte
#37826 String.substring() is returning a String. So, if you wish to check only the first character of that returned string, you need to use "char charAt(unsigned int index)".
You code will then look like :
Code: Select allAx = submit.substring(0,1).charAt(0);

But it is a bit redundant, you should go directly to your goal :
Code: Select allAx = submit.charAt(0);
User avatar
By xtal
#37827 thx I'll give it a try --- I know very little about Arduino and C.....
I'm trying to port my LUA code to Arduino, its been interesting....

Is there anything like CallBack in Arduino, I need to capture async serial from a PIC , but do not want to loop waiting for it.

I there a good ref doc any where I can download? I havn't found any total doc, I can find individual pages.
User avatar
By martinayotte
#37837 For the Serial Callback, there is something on Native Arduino which is call SerialEvent.
In fact the core is calling such callback when an event occured but it is handled while handling the loop(), it is not interrupt based.
Unfortunately, on ESP, it is not implemented.
There is maybe a workaround if you wish to put you hands in the core files. If not, better stick with the loop() using serial.available(), but it doesn't prevent you from doing something else when no serial activity is detected, and you can manage your own buffer.

For the docs, there are plenty around, especially on the GitHub : https://github.com/esp8266/Arduino