• Welcome to PlanetSquires Forums.
 

firefox /curl /whatever

Started by raymw, November 10, 2021, 11:52:18 AM

Previous topic - Next topic

raymw

Hi, a bit off topic, but maybe someone has an idea.
I'm trying to access text on a web page, and if ia word matches one in my list, then it will play a sound file on my local pc.
The situation is the web page is the interface to my 3d printer, accessed via wifi. The printer is in another room, and I would like a sound to happen on my local pc when an error occurs, or print ends, say.  I was looking into having a command line (windows 10) or a batch file, to every minute or so, save the page, do a word search, and if a key word is found to take the appropriate action.
Curl will not handle the css/java, Firefox, will do it nicely, you can save the page as text, but not afaik from the command line. This is an area that I'm not familiar with, so any help appreciated. It was  only today I found curl, and realised firefox could run from command line.
Any suggestions welcomed.

philbar

Maybe not the simplest idea, but WinFBX has a CWinHttpRequest Class that you can use to connect to a website, request a page, and receive the page as a string. You could then search the string for your key words. It could be a fairly short program that you run periodically, or it could lurk in the background and activate itself on a timer. I haven't actually tried this, so I can't say if there are any gotchas.
Hey, that would make it on topic.


raymw

Thank. It is surprising how complicated simple things can become. I actually, after pushing the software developers, found that there is a web based text file written, not sure how often, but giving the latest status of the printer. This is in plain text and curl will find it and save as a text file. I've found a couple of key words in the state field, -'completed' and 'paused', there maybe more, but nobody has said. I've written a couple of bat files to play m4a files (never heard of that format, but seems to be what w10 sound recorder defaults to), and found that *c:vlc --qt-start-minimized --play-and-exit soundFilename " will play them in the background, without flashing media players on the screen. My current problem, is that having done a simple gui, with  a start and stop button and a text box for the time period, I've forgotten how to deal with sleep. i.e. hitting the start button reads the file, speaks message if paused or completed, goes to sleep for a while, wakes up and repeats. The snag is, that other than closing the window, I can't break out of the sleep loop.  I'm getting mixed up with micro-processor programming, where you can sleep until an interrupt. I was hoping that hitting the stop button would interrupt the 'sleep loop', and allow the time settings to be changed/whatever. All that happens is that the whole form gets 'greyed out', it is not responding (but still runs the loop). There is a simple answer, i just can't think of it.

raymw

Another annoyance, is that running a cmd line bat task, opens the cmd window. Not sure if i can get around that

SeaVipe

Hi Ray, Not sure how helpful this is but I've used the TIMER function a few times:

'' Example of using TIMER function
'' Note: see text about correct waiting strategies
Dim Start As Double
Print "Wait 2.5 seconds."
Start = Timer
Do
    Sleep 1, 1
Loop Until (Timer - Start) > 2.5
Print "Done."

In one usage I was checking for an event to exit the Do and in another version, the loop waited for a keystroke.
Clive Richey

raymw

Thanks, I'll try that. I thought that the sleep, when used, sort of turned off the process and released the cpu/etc, but using timer kept it all running. I guess it doesn't matter so much with the more modern multicore cpus.
Instead of playing back a recorded message of me saying 'printer paused', I thought I'd use narrator or something to read a small text file containing the phrase. There seems to be problems with all the text file to speech systems out there, at least for me. Back in the day of the Tandy (radio shack) trs80, i made a speech unit, parallel printer interface, fed it a file of phonemes, simple.

raymw

I remember something about having to use something like a refresh, but have found that AfxDoEvents in the loop will let it break out of the loop when loop finishes., but not immediately.  It can take a while running the bat files. Not sure if possible to run them starting in a minimised cmd window. I've used the timer loop, as suggested