msloth / lgtv.js

Control LG WebOS TV using node.js
MIT License
252 stars 119 forks source link

Fix for finding tv on firmware 1.4.0-2507 #15

Closed avenantsoftware closed 2 years ago

avenantsoftware commented 8 years ago

as you wrote here:

"Update, with the latest firmware as of today, the 1.4.0-2507(afro-ashley), the nmap looks like below. Also, I don't see it advertising itself over SSDP like before, nor answer to the ssdp query as it did before."

that's because in index.js

you have in the ssdp discovery this: urn:dial-multiscreen-org:service:dial:1

it should be: urn:lge-com:service:webos-second-screen:1

you can also send messages with a custom icon with a base64 encoded string of an image

{\"id\":\"message\",\"type\":\"request\",\"uri\":\"ssap://system.notifications/createToast\",\"payload\":{\"message\": \"%@\", \"iconData\": \"%@\", \"iconExtension\": \"png\"}}

msloth commented 8 years ago

Hmmm, perhaps my tv decided to be silent for some other reason that evening then. It didn't respond to the original query, nor many others I tried, until I arrived at the one in the repo now. I guess that that SSDP query string risks getting responses from non-LG devices too. I'll try again with the lge-com string.

Thanks for the icon tip! That's awesome, gonna test it later :) Can you give me an example with a complete (preferably safe pic :) ) string? Ie, I should replace the %@ in iconData with the base64-encoded pic, and the one in message with just my message string, right?

avenantsoftware commented 8 years ago

yeah the %@ is from objective-c, I created everything in objective-c also lol.

You can use this url to create a base64 string from an image: http://www.askapache.com/online-tools/base64-image-converter/

I use this code below in my fork of Pullover, to convert images in pushover messages in node to base64

I need to first save the image to disk and then convert it to base64

                           // get message icon from pushover site
            request.get({url: iconPath, encoding: 'binary'}, function (err, response, body) {
                fs.exists(message.icon + '.png', function(exists) {
                    if (!exists) {
                        // save message icon 
                        fs.writeFile(message.icon + '.png', body, 'binary', function(err) {
                            if(err) {
                                console.log(err);
                            }
                        }); 
                    }
                });
            });

            // convert stored message icon to base64
            var iconData = base64_encode(message.icon +'.png');

and the function:

                          function base64_encode(file) {
                          // read binary data
                        var bitmap = fs.readFileSync(file);
                         // convert binary data to base64 encoded string
                        return new Buffer(bitmap).toString('base64');
                         }
avenantsoftware commented 8 years ago

because of your code I was able to create everything also in objective-c, my TV is now part of my Home Automation, everything is displayed as toast messages on my tv, I use python scripts to get newsfeeds and send the headlines as pushover mesages, and then with my fork of Pullover I get news feeds as pushover messages on my TV with a custom icon for every news feed, once I created it in objective-c I added it to my home automation os x app: Smart Home => http://www.macupdate.com/app/mac/53802/smart-home now I get every Home Automation message on my TV, like lights, devices, thermostat, alarm etc..

msloth commented 8 years ago

That's awesome! Cool! Yeah, my main motivation apart from curiosity was making it easy for my daughter to start her favorite things without navigating through youtube and kodi, but never got that far. Now we are watching too various things so that starting just a few fav's isn't that useful anymore.