x
This website is using cookies. We use cookies to ensure that we give you the best experience on our website. More info. That's Fine
HPC:Factor Logo 
 
Latest Forum Activity

I made an IP cam viewer (WCE 2.11 and up)

1 2
Karpour Page Icon Posted 2014-10-11 1:57 PM
#
Avatar image of Karpour
Subscribers
H/PC Philosopher

Posts:
439
Location:
Austria
Status:
Just if anyone cares, here's the source code! Of course the device needs enough memory to have one *gasp* 640*480 bitmap stored, but once you free up enough it should work for a while! It'll work for FOSCAMs and similar IP cameras that output 640x480 jpegs via (very insecure) GET transmission of your credentials

 
import java.awt.BorderLayout; 
import java.awt.Frame;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.MalformedURLException;
import java.net.URL;

class IPCamViewer extends Frame implements ActionListener {

/**
*
*/
private static final long serialVersionUID = 1L;
private MediaTracker mediatracker;
private ImageCanvas imageCanvas;
private Image image;
private String host;
private int port;
private String username;
private String password;
private String url;
private int refreshRate = 5000; // refresh rate in ms

IPCamViewer(String host_, int port_, String username_, String password_) {
super("IP Cam Viewer - "+host_+":"+port_);
this.host = host_;
this.port = port_;
this.username = username_;
this.password = password_;
url= "http://"+host+":"+port+"/snapshot.cgi?user="+username+"&pwd="+password;

// Setup
setLayout(new BorderLayout());
setSize(640, 480);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowevent) {
System.exit(0);
}
});
show();

// create Image Canvas
imageCanvas = new ImageCanvas();
mediatracker = new MediaTracker(imageCanvas);
image = null;
//updateImage();

while(true){
try {
updateImage();
Thread.sleep(refreshRate);
} catch (InterruptedException e) {
System.out.println("Interrupted");
return;
}
}
}

public void updateImage(){
if(image!= null){
mediatracker.removeImage(image, 0);
image = null;
System.gc();
}
try {
image = getToolkit().getImage(new URL(url));
} catch (MalformedURLException e) {
System.out.println("Bad url");
}
if (image == null) {
System.out.println("Error loading image");
return;
}
mediatracker.addImage(image, 0);
try {
mediatracker.waitForAll();
} catch (Exception exception) {
exception.printStackTrace();
}
imageCanvas.setImage(image);
add(imageCanvas, "Center");

show();
}

public static void main(String args[]) {
new IPCamViewer("<hostname of IP cam>",<port>,"<username>","<password>"); // fill in data here
}

public void actionPerformed(ActionEvent actionevent) {
System.out.println(actionevent.getActionCommand());
if (actionevent.getActionCommand().equals("Close"))
System.exit(0);
}
}
 Top of the page
1 2
Jump to forum:
Seconds to generate: 0.156 - Cached queries : 58 - Executed queries : 9