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.
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.
Attachment | Size |
---|---|
OLED xAP-OSD demo.zip | 636.94 KB |
OLEDApplet.lua | 2.1 KB |
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
Hi Garry,
I Just dopped you an Email via the forums here for some compiling issues.
thanks Andrew
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);
}
}
}