ESP8266+OLED+xAP-OSD script

4 replies [Last post]
garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011

Another proof of concept.

Here is some firmware for the ESP8266 that will accept the following osd style xap packet to control an OLED display.

xap-header
{
v=12
hop=1
uid=FF111300
Class=xAP-OSD.Display
Target=dbzoo.eap.display
}
Display.Text
{
Line1=Incoming : Mobile Phone call
Line2=Telephone, 07887 123456
Size2=2 }

I have added the optional size function such that size2=2 means line2 will have size 2.

lines can be of size 1 (default) or 2.

My display has 8 lines available. A size 2 takes up two lines such that in the example above line 4 in the next available line.

still rough round the edges but working nicely so far.

Garry.

 

AttachmentSize
OLED xAP-OSD demo.zip636.94 KB
OLEDApplet.lua2.1 KB
brett
Offline
Providence, United States
Joined: 9 Jan 2010
OLED arrived today

Garry,

My OLED arrived today so I compiled up your demo.  It rocks!
I'll tinker a little with the logic and get rid of those repeating code blocks to make it neater.

Brett

UPDATE:  This function can be a tad more compact from what you wrote.

void mqttDataCb(uint32_t *args, const char* topic, uint32_t topic_len, const char *data, uint32_t data_len)
{
    MQTT_Client* client = (MQTT_Client*)args;

    xAPFrame frame;
    // *data is altered by this call.
    parseMsg(&frame, (unsigned char *)data, data_len);
   
    char *class = xapGetValue(&frame,"xap-header","class");
    if(class == NULL || strcasecmp(class,"xAP-OSD.Display")) return;   
   
    int i;
    for(i=0; i<8; i++) {
        char buf[6];       
        os_sprintf(buf,"line%d", i+1);
        char *text = xapGetValue(&frame,"Display.Text",buf);
        if(text) {
            os_sprintf(buf,"size%d", i+1);
            char *size = xapGetValue(&frame,"Display.Text",buf);
            int s = 1;
            if(size) {
                s = atoi(size);
                if(s < 1) s = 1;       
                if(s > 2) s = 2;
            }
            OLED_Print(0, i, text, s);
        }               
    }
}

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Thanks Brett,Always good to

Thanks Brett,

Always good to see your improvements.

i knew the repeating code blocks were ugly but couldn't think of the best way to remove them.

must say I find the c code quite difficult. I've bought a book to read so hopefully will improve as time goes on!

that said, I was just pleased I could write something that worked!

cheers,

Garry

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Yes C can be like that, it

Yes C can be like that, it takes time to grok it.  Your code did work "out of the box" so its a gone well as far as I'm concern and only minor tweaks.

DEFECT: In the email you see "char buf[5];" in the above post I've modified this to "char buf[6];" as its 1 byte short and the sprintf() would be writting into unallocated memory.  My bad even I make mistakes :)

Brett

AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012
Hi Garry, I Just dopped you

Hi Garry,

 

I Just dopped you an Email via the forums here for some compiling issues.

 

thanks Andrew

Hardware Info