ESP8266+OLED+xAP-OSD script

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.

Member for

16 years 10 months

brett

11 years 7 months ago

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

Member for

15 years 7 months

garrydwilms

11 years 7 months ago

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

Member for

16 years 10 months

brett

11 years 7 months ago

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

Member for

13 years 11 months

AndrewJ

10 years 8 months ago

Hi Garry,

 

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

 

thanks Andrew

OLEDApplet.lua (2.1 KB)