Java and Interfacing with Sony IP Camera - java

I usually don't like to post questions because I would rather figure things out myself, but I am ready to pull my hair out with this one. I am trying to interface with a Sony IP Camera using Java. One of the products of the company I work for uses a Sony IP camera (IPela EP550). I have been tasked with writing the new interface. I can connect to the stream using the VLC ActiveX embedded control, but I can't manipulate the PTZ of the camera from in Java. If I type: "http://xxx.xxx.xxx.xxx/command/ptzf.cgi?Move=left,0" in a web browser it will move, but I have tried every bit of code I can find with Google to get it to move with no success. This last thing I tried (because a page on Oracle said all I should have to do is open the connection):
URL url1 = new URL("http://xxx.xxx.xxx.xxx/command/ptzf.cgi?Move=left,0&t="+new Date().getTime());
HttpURLConnection con = (HttpURLConnection)url1.openConnection();
Any help will be appreciated. Thank you.
Joe

Check out whether the camera needs login.
type the url in the browser, get HTTP request header and put header data into your code!

I figured out how to do this. I am posting the solution in case anybody is looking to fix a similar problem. I took the basic idea in this Dr. Dobbs article and used it to get movement from the camera. I don't yet know why I can't get the camera to respond with URLConnection and HttpURLConnection, but using a Socket and PrintWriter to specifically print the GET request to the socket.

Related

How to verify that Wifi AP or Cell have internet?

I'm looking for best technique to verify internet over WiFi or Cell. Let's say you are connected to some AP but you don't now if internet exists.
Today I have 2 options by using HttpURLConnection:
Download file from cdn server
to send request to trust web page like google.com and get response 200.
Any other ways?
All suggestions would be appreciated.
On some level, 'ability to access internet endpoints' is equivalent to 'having internet access'. You could consider some algorithm:
for (Endpoint site : theEntireInternet) {
if (can connect to site) return true;
}
return false;
which will conclusively establish connectivity. In other words, being able to connect to any one site is sufficient positive proof, but theoretically you would need to enumerate every site to prove non-connectivity. In practice, checking a few major sites is obviously sufficient. Otherwise (without some sort of meta-information about networks, ISPs, etc; which is unavailable) there's no way to conclusively demonstrate "internet" connectivity other than... connecting to the internet.
Of course as you comment, checking various internet-based applications can't hurt either; it's just a different form of an equivalent technique.
See the Telephony Manager and it's getDataSate() method it has four state
DATA_DISCONNECTED
DATA_CONNECTING
DATA_CONNECTED
DATA_SUSPENDED
You can get the instance of telephony manager --
TelephonyManager tm = (TelephonyManager)getSystemService(Telephony_Service);
Here it is:
to see the state of the data connection on the cell network
and for the WIFI, I would use this public class WifiInfo. From there you can use getIpAddress() or getDetailedStateOf(...)
Hope it's helpful.

How to use Javapns to Support Apple's Enhanced Notification Format

Greetings,
I am creating a Java based server to create push notifications for Apple's iOS APNs service. I have found Javapns on google code which seems to provide a simple basic framework to communicate with APNs, and which seems to be fairly wide used.
http://code.google.com/p/javapns/
However, reading Apple's docs, there is an "enhanced format" for notifications which supports "expiry" i.e. setting a time (well, in seconds) for a notification to expire if it hasn't yet been delivered. I do not see any way to set this using Javapns, and I am unsure how the APNs service handles expiry of notifications if you do not explicitly set it. So,
Does anyone know how to support the enhanced notification format of APNs specifically how to set the expiry?
Does anyone know how Apple handles notification expiry if it isn't explicitly set?
Does anyone have any suggestions that don't require me to start from scratch, as the server is currently functional as is?
Thanks in advance.
Andrew
I have recently made substantial contributions to the JavaPNS project, which lead to the release of JavaPNS 2.0 a few days ago. That version provides full support for the enhanced notification format, including the ability to set your own expiry.
Sylvain
Nice that you found the java library... to bad you didn't read the docs there.
I'll post some of the highlights below:
The existing code uses the 'Simple notification format' which does not return an error EVER.
See docs at:
http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html
I've tried updating to the 'Enhanced notification format' which is supposed to return an error, but I'm unable to get any errors back from the APNS. (also in the link above)
With the Enhanced format, the connection isn't being dropped immediately after sending data, but I'm not getting anything back from my socket.getInputSocket.read() call.
This issue will have to be tabled until I have more time to troubleshoot.
(Someone else commented)
Thanks a lot for looking into it.
I got the same result as yours. Maybe it has something to do with Apple Gateway.
So... you could:
1) Build your own
2) Help improve the existing library
3) Try another library like: https://github.com/notnoop/java-apns
4) Do nothing
Enhanced ios push here.
To send a notification, you can do it in three steps:
Setup the connection
ApnsService service =
APNS.newService()
.withCert("/path/to/certificate.p12", "MyCertPassword")
.withSandboxDestination()
.build();
Create and send the message
String payload = APNS.newPayload().alertBody("Can't be simpler than this!").build();
String token = "fedfbcfb....";
service.push(token, payload);
To query the feedback service for inactive devices:
Map<String, Date> inactiveDevices = service.getInactiveDevices();
for (String deviceToken : inactiveDevices.keySet()) {
Date inactiveAsOf = inactiveDevices.get(deviceToken);
...
}

Save Java Applet Variable to Mysql

Hi
I've done a lot of research on the best way to communicate between a java applet and MySql Database.
I have a tune player which I have students logging onto, it's a java applet with a speed slider. I want to save the speed that they play each tune at so it goes back to the same speed the next time they open that tune.
It seems I have a number of options, none of which seem very neat.
Use a javascript function to
periodically check the speed and
save it to a cookie, then each page
of the site would have to check
cookies relationg to each tune.
Make each link on the page call a
javascript function to check the
speed variable in the applet and add
it to a perameter in the url then
redirect so the next php page can
save the speed to a database. This
way when the user navigates away the
speed will be saved, but this won;t
work if the back button is used.
Is there a better way of doing this?
Use the JNLP API and the problems should be solved.
Since Java 1.6.0_10+, it is possible to use the Java Web Start API services (JNLP API) within an embedded applet. The JNLP API provides the PersistenceService. Here is a small demo. of the PersistenceService.
If the user hits the back button (or otherwise leaves the page), the destroy() method will be called. Override the destroy method and persist the data at that time.
No need to use JavaScript.
The java code below posts variables to a PHP script on the web server then
shows the server response on the console
private void post()
throws MalformedURLException, IOException
{ URL url;
URLConnection con;
OutputStream oStream;
String parametersAsString;
byte[] parameterAsBytes;
String aLine; // only if reading response
parametersAsString = "msg=hi&to=memo";
parameterAsBytes = parametersAsString.getBytes();
// send parameters to server
url = this.getCodeBase();
url = new URL(url + "scriptfile.php");
con = url.openConnection();
con.setDoOutput(true);
// setDoInput(true); // only if reading response
con.setDoInput(false);
con.setRequestProperty("Content=length", String.valueOf(parameterAsBytes.length));
oStream = con.getOutputStream();
oStream.write(parameterAsBytes);
oStream.flush();
// read response from server & show the server response on the Java console or whatever ...
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
aLine = in.readLine();
while (aLine != null)
{ System.out.println(line);
aLine = in.readLine();
}
in.close();
oStream.close();
}
I'd suggest you get the applet to update the database. Whenever the speed slider changes you can fire off an update to the database, or you might need to coalesce multiple changes into one request depending on usage.
When the applet changes tune it can also do its own lookup of the correct speed.
Note that the applet will probably not be able to hit the database directly - browsers should restrict what I/O operations are available to applets - but you should be able to get the applet to hit a URL on the server that will actually perform the update. Signing the applet may let you hit the database but you should read up on the applet security model and the various browser quirks first.
It's not really clear how all of this is set up since you don't have a lot of details. However, assuming that you have an actual Java applet, I'd say the following:
If the Java applet requires a login (that is, it knows who the user is) then it can store the preference on the server. To do this you could have the applet connect to the server using JDBC, which isn't generally a good idea for internet-facing applets, or you could have the applet send a message to a server process such as a web server. That process connects to the mysql server.
The applet can communicate directly with the browser using Javascript. So you can have the applet set the cookie when the slider changes, instead of having the Javascript set it.

Android/Java: Simulate a click on this webpage

Last year I made an Android application that scrapped the informations on my train company in Belgium ( application is BETrains: http://www.cyrket.com/p/android/tof.cv.mpp/)
This application was really cool and allowed users to talk with other people in the train ( a messagery server is runned by me) and the conversations wre also on Twitter: http://twitter.com/betrains
Everybody in Belgium loved it. The company tried to avoid us to use their data, make some users websites closed, but their was some lawyers that attack the company and finally we have no more problems and the websites are open: http://blog.tuinslak.org/2010/07/irail-is-back
So, legally my application is ( for now) totally correct and legal, but I get no help from the train company.
So my question is a little help to get the datas. I am now an android/java beginner and spend some weeks to try to find a solution, but maybe people like will fint it in a few minuts.
So the problem is the next one. You may have a look at the following URL, and you will find 2 cities names within URL: Mons and Tournai, and also informations on the date and time. That was the old method that worked one year:
http://hari.b-holding.be/Hafas/bin/query.exe/en?&REQ0JourneyStopsS0A=1&REQ0JourneyStopsS0G=MONS%20[b]&REQ0JourneyStopsZ0A=1&REQ0JourneyStopsZ0G=TOURNAI%20[b]&REQ0JourneyDate=27.010.10&REQ0JourneyTime=19:030&Timesel=depart&ViaName=&ViaMode=NEE&DateMode=ANDERS&PLANNER=TRUE&start=1&queryPageDisplayed=yes
But now, the URL bring me on a confirmation page and I have to click on the confirm button to get to the next page.
So my code won't work anymore, I need to click on this button programmatically to arrive on the correct webpage.
Have you any idea on how to simulate a click on this button? For now my code is the classic scrapping code with the URL given a few line on the top. I assumed that the Url give me the result page. That was the case till last week.
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet get = new HttpGet(mon_url);
HttpResponse response;
try {
response = httpclient.execute(get);
HttpEntity entity = response.getEntity();
BufferedReader buf = new BufferedReader(new InputStreamReader(entity.getContent()));
etc...
Have you any idea on how to improve the code?
As the software is free, I cannot send paypal money, but a whole country would be really thankfull to the man that might help!
Thank a lot.
Instead of trying to automate clicking the JavaScript button, try monitoring what request is sent and then replicate this in your app. There are various firefox extensions that will help you do this, such as TamperData, Firebug, and LiveHttp.

SDP message construction?

I was wondering can anyone point me to a good tutorial on how to construct a SDP message.
I have read the basics and can construct and understand the parameters but I just can't seem to get it to work.
I either get a not acceptable here reply or no reply at all, this is after I get 100 Trying and 180 ringing back.
So my SIP works but it doesn't like the SDP Data.
Its currently constructed like this:
String sdpData = "v=0\r\n"
+ "o=- 019078020 0"
+ " IN IP4 sip.ciceronetworks.com\r\n" + "s=MySession\r\n"
+ "c=IN IP4 sip.ciceronetworks.com\r\n"
+ "t=0 0\r\n" + "m=audio 6002 RTP/AVP 0\r\n"
+ "a=sendrecv\r\n" + "a=rtpmap:0 PCMU/8000\r\n" + "a=ptime:20\r\n"+ "a=fmtp:97 mode=20\r\n";
byte[] contents = sdpData.getBytes();
request.setContent(contents, contentTypeHeader);
And while like that I get 100 trying then 180 ringing but when I accept the call on the other end I get nothing back at all, it seems to just crash, I also get "Audio device Error" on the pc client that I try ringing.
Anyone any ideas?
The issue could be really simple: you seem to forgot the newline after "a=sendrecv". :-)
Anyway, here's an advice:
For testing purposes you are probably better off using a tool rather than jumping right in and writing parts of the protocol. You can use sipp for this purpose, it makes a great tool for testing SIP networks. Other than that you could of course just sniff the network traffic between two working SIP devices and see how it differs from your traffic.
EDIT:
I missed this one before:
You should omit a=fmtp:97 mode=20, as the session description is invalid this way: You may only use the format parameter attribute for codecs that are mentioned in the media line. Codecs are identified via the payload type number (0=PCMU, 8=PCMA, 18=G723, ...). Some codecs don't have officially assigned numbers, for these the dynamic range 96-127 should be used: user agents are free to assign a number in this range via an rtpmap attribute. So, unless you specify which codec you mean by 97, there is no way for the other user agent to know which codec the format parameters should be applied to.
Paprika is right: the a=fmtp:97 mode=20 is simply wrong (and looks like it's part of an iLBC codec offer). You didn't offer codec 97, you offered codec 0 (PCMU).
Note that the a=fmtp:97 shouldn't hurt you, it's just spurious.
The most likely problem is that you are not sip.ciceronetworks.com - i.e. your c= line (and m= line) said "send my media to port 6002 at sip.ciceronetworks.com". I suspect your PC's IP address is not the same as sip.ciceronetworks.com, and/or there's a firewall/NAT between you and the other end.
It probably isn't your problem, but the o= line is wrong per the spec
From RFC 4566:
o=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>
Getting VoIP to work is not as simple as the RFCs or cookbook explanations would imply....
I found a good article which deals with SDP (Session Description Protocol). It is also in relationship with an SDK which is called Ozeki VoIP SIP SDK. If you combine these things you will be able to create a softphone for instance.
There is also a brief overall about SDP.
Working with SDP in VoIP SIP calls is an interesting topic for those who wish to develop their own softphone or webphone application or what you desire.
SDP describes multimedia communication session for the purposes of session announcement, session invitation, and parameter negotiation.
The usage of an SDK can take a lot of burden from one's shoulder bucasue flexibility and high compatibility is assured.
For more information regarding SDP in connection with an SDK to build own applications you can have a look at the mentioned article if you Google for: "Working with SDP in VoIP SIP calls"

Categories