Query for Battery capacity - android
I need help. I just want to make application that reads battery capacity, like read in mAh/mA. Anyone can help me please?
I've read another thread about this, but I was confused because I need an integer from battery capacity. For example, my android has a battery with capacity 2500 mAh
and I need that integer of capacity(2500) where I want to include that number in my calculation.
Thanks for the help.
This is code that I want to change, I am just confused where it must be changed.
public void getBatteryCapacity() {
Object mPowerProfile_ = null;
final String POWER_PROFILE_CLASS = "com.android.internal.os.PowerProfile";
try {
mPowerProfile_ = Class.forName(POWER_PROFILE_CLASS)
.getConstructor(Context.class).newInstance(this);
} catch (Exception e) {
e.printStackTrace();
}
try {
double batteryCapacity = (Double) Class
.forName(POWER_PROFILE_CLASS)
.getMethod("getAveragePower", java.lang.String.class)
.invoke(mPowerProfile_, "battery.capacity");
Toast.makeText(MainActivity.this, batteryCapacity + " mah",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
Yes, your code gives total mAh capacity. You can change that function to return the value like this:
public Double getBatteryCapacity() {
// Power profile class instance
Object mPowerProfile_ = null;
// Reset variable for battery capacity
double batteryCapacity = 0;
// Power profile class name
final String POWER_PROFILE_CLASS = "com.android.internal.os.PowerProfile";
try {
// Get power profile class and create instance. We have to do this
// dynamically because android.internal package is not part of public API
mPowerProfile_ = Class.forName(POWER_PROFILE_CLASS)
.getConstructor(Context.class).newInstance(this);
} catch (Exception e) {
// Class not found?
e.printStackTrace();
}
try {
// Invoke PowerProfile method "getAveragePower" with param "battery.capacity"
batteryCapacity = (Double) Class
.forName(POWER_PROFILE_CLASS)
.getMethod("getAveragePower", java.lang.String.class)
.invoke(mPowerProfile_, "battery.capacity");
} catch (Exception e) {
// Something went wrong
e.printStackTrace();
}
return batteryCapacity;
}
The getAveragePower function returns the average current
in mA consumed by the subsystem. In this case subsystem string is battery.capacity which returns the battery capacity.
See class code here:
https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/com/android/internal/os/PowerProfile.java
And if you really want that value as int, just change it like this:
int bc = getBatteryCapacity().intValue();
Related
List all files, recursively, in Android Dropbox API
How can I list all files, recursively in DropBox folder? I tried code below but returns no result: result = dbxClient.files().search("", "*"); And this returns files in path, not subfolders: result = dbxClient.files().listFolder(path);
You can get a ListFolderBuilder from listFolderBuilder and use the withRecursive option to list out sub-items as well. Be sure to check ListFolderResult.hasMore to see if you should call back to listFolderContinue to get more results though.
You can check this link, navigate to inner class 'FolderScanTask'. It contains working code for Android: https://github.com/ControlX/Android-Dropbox-UploadImage-To-SpecificFolder-By-FolderSelection/blob/master/app/src/main/java/io/github/controlx/dbxdemo/MainActivity.java This is work in progress, here I'm just making an ArrayList for parent folders, has more logic as suggested by Greg is already there you just need to fill in that. Code Snippet for the same: String path = ""; DbxClientV2 dbxClient = DropboxClient.getClient(ACCESS_TOKEN); TreeMap<String, Metadata> children = new TreeMap<String, Metadata>(); try { try { result = dbxClient.files() .listFolder(path); } catch (ListFolderErrorException ex) { ex.printStackTrace(); } List<Metadata> list = result.getEntries(); cs = new CharSequence[list.size()]; arrayList = new ArrayList<>(); arrayList.add("/"); while (true) { int i = 0; for (Metadata md : result.getEntries()) { if (md instanceof DeletedMetadata) { children.remove(md.getPathLower()); } else { String fileOrFolder = md.getPathLower(); children.put(fileOrFolder, md); if(!fileOrFolder.contains(".")) arrayList.add(fileOrFolder); } i++; } if (!result.getHasMore()) break; try { result = dbxClient.files() .listFolderContinue(result.getCursor()); } catch (ListFolderContinueErrorException ex) { ex.printStackTrace(); } } } catch (DbxException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } Here ArrayList is just for my use wherein I'm just making a list of only folders. So, modify accordingly.
How to get specific information of an Android device from "/proc/cpuinfo" file?
How can I parse /proc/cpuinfo virtual file of my Android tablet to get information of the processor's core and clockspeed? I don’t need all information provided by the above file; just these two bits. Can someone please help?
It is not clear if you want this information inside your app, or just for your own use. you can get this information on with adb: adb shell cat /proc/cpuinfo If you want to use this information in your app, create a simple function to return a Map<String,String>, for example, public static Map<String, String> getCpuInfoMap() { Map<String, String> map = new HashMap<String, String>(); try { Scanner s = new Scanner(new File("/proc/cpuinfo")); while (s.hasNextLine()) { String[] vals = s.nextLine().split(": "); if (vals.length > 1) map.put(vals[0].trim(), vals[1].trim()); } } catch (Exception e) {Log.e("getCpuInfoMap",Log.getStackTraceString(e));} return map; } Note, this will not get multiple cpus information, overwrites. Most of the values are similar anyways. or Modify to create List of CpuInfoMaps. try, Log.d("getCpuInfoMap test", getCpuInfoMap().toString());
I hope its not too late for an answer but, this is how i get the current frequency for a specific cpu core: public class MainActivity extends Activity{ private static final int INSERTION_POINT = 27; private static String getCurFrequencyFilePath(int whichCpuCore){ StringBuilder filePath = new StringBuilder("/sys/devices/system/cpu/cpu/cpufreq/scaling_cur_freq"); filePath.insert(INSERTION_POINT, whichCpuCore); return filePath.toString(); } public static int getCurrentFrequency(int whichCpuCore){ int curFrequency = -1; String cpuCoreCurFreqFilePath = getCurFrequencyFilePath(whichCpuCore); if(new File(cpuCoreCurFreqFilePath).exists()){ try { BufferedReader br = new BufferedReader(new FileReader(new File(cpuCoreCurFreqFilePath))); String aLine; while ((aLine = br.readLine()) != null) { try{ curFrequency = Integer.parseInt(aLine); } catch(NumberFormatException e){ Log.e(getPackageName(), e.toString()); } } if (br != null) { br.close(); } } catch (IOException e) { Log.e(getPackageName(), e.toString()); } } return curFrequency; } } From here its a piece of cake, you simply call the method :-D int core1CurrentFreq = getCurrentFrequency(1, this); Sometimes the cores go offline, in which case the file path will not exist and -1 will be returned NOTE. the returned value is in KHz MHz value is core1CurrentFreq / 1e3 GHz value is core1CurrentFreq / 1e6 Some explainations on the getCurFrequencyFilePath() method since it is not all that clear. Current frequency is usually stored in the file: scaling_cur_freq The file path is: "/sys/devices/system/cpu/cpu(XX)/cpufreq/scaling_cur_freq" where (XX) is substituted for the cpu core number eg: "/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq" The INSERTION_POINT variable is nothing more than the index of (XX), the point at which we want to place the number corresponding to the cpu core I suggest you take a look at some of the other files in the cpufreq folder, you can use them to get other information like maximum and minimum frequency, list of availables frequencies etc. Click this Link and scroll down to heading 3
Eclipse - Functions issue [duplicate]
This question already has answers here: How do I compare strings in Java? (23 answers) Closed 8 years ago. I'm trying to get text from server and then check it a to know what actions to take with the text adopted. The problem is that when I try to check if the received text for example is "Exited" the query always return the value "false" when the received text is really "Exited". Here is the code : class Get_Message_From_Server implements Runnable { public void run() { InputStream iStream = null; try { iStream = Duplex_Socket_Acceptor.getInputStream(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Create byte array of size image byte[] Reading_Buffer = null; try { Reading_Buffer = new byte [Duplex_Socket_Acceptor.getReceiveBufferSize()]; //New_Buffer = new byte [100]; } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } byte[] Byte_Char_1 = new byte[1]; int Byte_String_Lenght = 0; //read size try { iStream.read(Reading_Buffer); String Reading_Buffer_Stream_Lenghtor = new String(Reading_Buffer); //System.out.println("full : " + Reading_Buffer_Stream_Lenghtor); Byte_String_Lenght = Reading_Buffer_Stream_Lenghtor.indexOf(new String(Byte_Char_1)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Convert to String Meassage = new String(Reading_Buffer); Meassage = Meassage.substring(0, Byte_String_Lenght);//The text that received Message_Getted = 1; } } The query : if(Message_1 != "Exited")//the message query { System.out.println("Continued 253"); continue; } Its always return the value - false its important to know that the message is in Utf - 8 encoding so how i can to fix the issue ?
If you compare strings by using oparators, Java will not look at the contents of the string but at the reference in memory. To compare String content in Java, you should use the following: String Message_1; // Hopefully has a value sent by the server if(Message_1.equals("Exited")) { // Do stuff when exited } else { // Do stuff when not exited }
String is a variable - and variables should start with lower Case letter - Please read Java Code conventions. Also to check if your message contains string you thing it should just do System.out.println(Message_1); and if the message contains what you expect you compare string doing if(Message_1.equals("Exited")) { System.out.println("Yes they are equal"); } else { System.out.println("No they are not"); } If this will print "No they are not" that simply means that your variable Message_1 is not what you think it is.. As simple as that. There is no such a thing as .equals method does not work. Its your variable that doesn't ;)
Ormlite ObjectCache returning old data
I'm using Ormlite on Android and with the ObjectCache enabled, I get old data back after updating the table with an UpdateBuilder and a ColumnExpression. I have read through the doc and it does not warn against using the UpdateBuilder with the cache enabled. The settings table should have just 1-5ish rows max. The updateColumnExpression seems like an easy way to allow only one of the rows to be true. Is this the expected behavior? public void setActiveSetting(String id) { try { UpdateBuilder<Settings, Integer> updateBuilder2 = getHelper().getSettingsDao().updateBuilder(); updateBuilder2.updateColumnExpression("active", "id = " + id ); updateBuilder2.update(); } catch (SQLException e){ e.printStackTrace(); } } And this is the call that returns the outdated data: public List<Settings> getSettings() { List<Settings> settings = null; try { settings = getHelper().getSettingsDao().queryForAll(); } catch (SQLException e) { e.printStackTrace(); } return settings; } And the settings DAO: public Dao<Settings, Integer> getSettingsDao() { if (null == settingsDao) { try { settingsDao = getDao(Settings.class); settingsDao.setObjectCache(true); } catch (java.sql.SQLException e) { e.printStackTrace(); } } return settingsDao; } Disabling the ObjectCache does return the correct data, but this data is fetched quite frequently, so I'd like to keep it. Thanks
Is this the expected behavior? Unfortunately, yes. If you had updated the object using dao.update(...); then the cache would know that the object needed to be refreshed. By using the UpdateBuilder to make mass changes to the table, there is no way for the cache to know which objects were affected. You will need to clear the cache after your call to the UpdateBuilder finishes.
Data being lost between Android device and python server using TCP
I'm somewhat new to network programming and am having some trouble. I am creating a JSON object on an Android device, connecting to a python server via TCP, and sending the JSON string. The connection gets accepted, but I keep losing the end of the string, so json.loads(json_string) is failing. Here is the relevant Android code: private class Worker implements Runnable { #Override public void run() { //create the network socket try { socket = new Socket(address, 4242); Log.i(TAG, "timeout: " + socket.getSoTimeout()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } packets = new ArrayList<JSONObject>(); for (jobs.moveToFirst(); jobs.isAfterLast() == false; jobs.moveToNext()) { String jobName = jobs.getString(jobs.getColumnIndex(JobMetaData.JobTableMetaData.JOB)); Uri.Builder updated = new Uri.Builder(); updated.scheme("content"); updated.authority(JobMetaData.AUTHORITY); updated.appendPath(jobName); updated.appendPath("member"); updated.appendPath(JobMetaData.MemberTableMetaData.CHANGED); updated.appendPath("true"); Cursor changed = getContentResolver().query(updated.build(), null, null, null, null); Log.d(TAG, "number of members " + changed.getCount()); //create a JSON object out of the editable properties for (changed.moveToFirst(); changed.isAfterLast() == false; changed.moveToNext()) { JSONObject json = new JSONObject(); for (String att : changed.getColumnNames()) { if (ListMetaData.validAtts.contains(att)) { try { json.put(att, changed.getString(changed.getColumnIndex(att))); } catch (JSONException e) { // TODO Auto-generated catch block Log.d(TAG, "JSON exception in DatagramService"); e.printStackTrace(); } } } //include the GUID and job name //for identification try { json.put(JobMetaData.MemberTableMetaData.GUID, changed.getString(changed.getColumnIndex(JobMetaData.MemberTableMetaData.GUID))); json.put(JobMetaData.JobTableMetaData.JOB, jobName); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } packets.add(json); } changed.close(); } Log.d(TAG, "entering send loop"); try { out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); out.flush(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } for (JSONObject packet : packets) { Log.d(TAG, "supposedly sending"); try { //now write the data Log.d(TAG, "packet string: " + packet.toString()); out.write(packet.toString()); out.flush(); } catch (IOException e) { } } try { out.write("Done"); out.flush(); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } stopSelf(); } And the test server that I am using (written in python): #!/usr/bin/env python import SocketServer import json class MemberUpdateHandler(SocketServer.BaseRequestHandler): def setup(self): print self.client_address, "connected" def handle(self): while True: self.JSONString = self.request.recv(8192).strip() if self.JSONString == "Done": return self.handleJSON() self.update() def handleJSON(self): JSONMember = json.loads(self.JSONString) print "GUID:", JSONMember['ManufacturingGUID'] print "Weight:", JSONMember['Weight'] def update(self): print "do something here" if __name__ == "__main__": ADDRESS = '' PORT = 4242 HOST = (ADDRESS, PORT) s = SocketServer.ThreadingTCPServer(HOST, MemberUpdateHandler) s.serve_forever() Here is the string that is being sent (it is long): {"DetailCheckedBy":"","SketchRight":"","DetailLength":"142.75","DetailedDate":"**NOT SET**","EngineerVerifiedBothConns":"False","HoldStatus":"Not held","RevisionLevel":"No Revision","MemberNumber":"28","RequestVerifySectionSize":"False","TieForcesRight":"False","InputBy":"","IFCFinishDate_4":"**NOT SET**","IFCFinishDate_5":"**NOT SET**","Weight":"438.408","IFCTaskUID_1":"","IFCFinishDate_1":"**NOT SET**","ErectorOrder":"","IFCFinishDate_2":"**NOT SET**","IFCFinishDate_3":"**NOT SET**","IFCTaskUID_4":"","IFCTaskUID_5":"","IFCTaskUID_2":"","SketchLeft":"","IFCTaskUID_3":"","ErectorSequences":"","ReasonRejected":"","MemberCategory":"","EngineerVerifiedLeftConn":"False","BarcodeId":"","ManufacturingGUID":"42bbf9cc-52da-4712-a5fc-e37c5a544c14","aess":"False","FabricationComplete":"**NOT SET**","UserComment2":"","UserComment3":"","LoadNumber":"","UserComment1":"","ErectionBolted":"**NOT SET**","RequestVerifyLength":"False","RequestVerifyGrade":"False","Painted":"False","HeatCertNumber":"","Route1Description":"","IsExisting":"No","ReceivedFromApproval":"**NOT SET**","BackCheckedBy":"","BatchNumber":"","CostCodeReference":"","PONumber":"","Piecemark":"B_25","ReleasedForFabrication":"**NOT SET**","MemberDescription":"BEAM","EngineerVerifiedMemberReady":"False","IFCTaskName_2":"","IFCTaskName_1":"","IFCTaskName_4":"","RequestVerifyMemberPosition":"False","IFCTaskName_3":"","Erected":"**NOT SET**","RevisionCheckedBy_3":"","IFCTaskName_5":"","RevisionCheckedBy_2":"","RevisionCheckedBy_1":"","EngineerVerifiedLeftComments":"","RequestVerifyLeftConnMaterial":"False","RequestEngineerVerify":"False","RevisionCheckedDate_3":"**NOT SET**","RevisionCheckedDate_2":"**NOT SET**","RevisionCheckedDate_1":"**NOT SET**","EngineerVerifiedLength":"False","BackCheckedDate":"**NOT SET**","SubmittedForApproval":"**NOT SET**","EngineerVerifiedSpecial":"False","CostCodeDescription":"","IFCStartDate_5":"**NOT SET**","TieForcesLeft":"False","Fireproofed":"False","ErectorAvailable":"False","RequestVerifyRightConnMaterial":"False","DetailCheckedDate":"**NOT SET**","ErectorNonSteelSupported":"False","BeamPent":"False","StockStatus":"","Sequence":"1","RequestVerifyLeftLoad":"False","DetailFinalCheckDate":"**NOT SET**","ErectorMemberPlaced":"**NOT SET**","InstanceStatus":"","EngineerVerifiedRightConn":"False","DateReceived":"**NOT SET**","MemberType":"Beam","ModelCheckDate":"**NOT SET**","ReasonForHold":"","EngineerVerifiedRightComments":"","ReceivedOnJobSite":"**NOT SET**","RequestVerifyRightLoad":"False","CostCodePrice":"0.0","NestStatus":"","DateDue":"**NOT SET**","ShopSequence":"","EngineerVerifiedSectionSize":"False","ActualLength":"144","InputDate":"**NOT SET**","ErectorCity":"Unknown","EngineerVerifiedSpecial_comments":"","Route4Description":"","EngineerVerifiedGrade":"False","RightLocation":"0.0xx144.0xx156.0xx","IFCFinishTime_2":"","IFCFinishTime_1":"","IFCFinishTime_4":"","Route3Description":"","IFCFinishTime_3":"","LoadStatus":"","ErectorLongitude":"","DateModelCompleted":"61299957600000","Grade":"##SEKRIT KODE!!##","IFCFinishTime_5":"","Route2Description":"","RequestVerifyCamber":"False","ProjectedFabricationComplete":"**NOT SET**","DetailedBy":"","DetailFinalCheckBy":"","Description":"W8x35","ProjectedShippedDate":"**NOT SET**","NestName":"","IFCStartDate_2":"**NOT SET**","IFCStartTime_1":"","IFCStartDate_1":"**NOT SET**","IFCStartDate_4":"**NOT SET**","IFCStartDate_3":"**NOT SET**","IFCStartTime_5":"","IFCStartTime_4":"","IFCStartTime_3":"","DateHeld":"**NOT SET**","IFCStartTime_2":"","LeftLocation":"0.0xx0.0xx156.0xx","Job":"Mobile_x_x_x_x_Demo_x_x_x_x_IN_x_x_x_x_2011","SpecialCutWeld":"False","RejectedBy":"","ErectionWelded":"**NOT SET**","RequestVerifyRightConnConfig":"False","Vendor":"","PackageNumber":"","RejectedByErector":"**NOT SET**","ModelCheckedBy":"","ApprovalStatus":"Not reviewed","RequestVerifyLeftConnConfig":"False","ErectorLatitude":"","LotName":"","ActualShipDate":"**NOT SET**","NestId":""} This is the error I get from the python server: ValueError: Unterminated string starting at: line 1 column 1435 (char 1435) which means that the string has been truncated to: {"DetailCheckedBy":"","SketchRight":"","DetailLength":"142.75","DetailedDate":"**NOT SET**","EngineerVerifiedBothConns":"False","HoldStatus":"Not held","RevisionLevel":"No Revision","MemberNumber":"28","RequestVerifySectionSize":"False","TieForcesRight":"False","InputBy":"","IFCFinishDate_4":"**NOT SET**","IFCFinishDate_5":"**NOT SET**","Weight":"438.408","IFCTaskUID_1":"","IFCFinishDate_1":"**NOT SET**","ErectorOrder":"","IFCFinishDate_2":"**NOT SET**","IFCFinishDate_3":"**NOT SET**","IFCTaskUID_4":"","IFCTaskUID_5":"","IFCTaskUID_2":"","SketchLeft":"","IFCTaskUID_3":"","ErectorSequences":"","ReasonRejected":"","MemberCategory":"","EngineerVerifiedLeftConn":"False","BarcodeId":"","ManufacturingGUID":"42bbf9cc-52da-4712-a5fc-e37c5a544c14","aess":"False","FabricationComplete":"**NOT SET**","UserComment2":"","UserComment3":"","LoadNumber":"","UserComment1":"","ErectionBolted":"**NOT SET**","RequestVerifyLength":"False","RequestVerifyGrade":"False","Painted":"False","HeatCertNumber":"","Route1Description":"","IsExisting":"No","ReceivedFromApproval":"**NOT SET**","BackCheckedBy":"","BatchNumber":"","CostCodeReference":"","PONumber":"","Piecemark":"B_25","ReleasedForFabrication":"**NOT SET**","MemberDescription":"BEAM","EngineerVerifiedMemberReady":"False","IFCTaskName_2":"","IFCTaskName_1":"","IFCTaskName_4":"","RequestVerifyMemberPosition":"False","IFCTaskName_3":"","Erected":"**NOT SET**","RevisionCheckedBy_3":"","IFCTaskName_ Any help would be greatly appreciated. Thanks in advance. UPDATE: I have updated the code to reflect my tinkering. The string received by the server is now {"DetailCheckedBy":"","SketchRight":"","DetailLength":"142.75","DetailedDate":"**NOT SET**","EngineerVerifiedBothConns":"False","HoldStatus":"Not held","RevisionLevel":"No Revision","MemberNumber":"28","RequestVerifySectionSize":"False","TieForcesRight":"False","InputBy":"","IFCFinishDate_4":"**NOT SET**","IFCFinishDate_5":"**NOT SET**","Weight":"438.408","IFCTaskUID_1":"","IFCFinishDate_1":"**NOT SET**","ErectorOrder":"","IFCFinishDate_2":"**NOT SET**","IFCFinishDate_3":"**NOT SET**","IFCTaskUID_4":"","IFCTaskUID_5":"","IFCTaskUID_2":"","SketchLeft":"","IFCTaskUID_3":"","ErectorSequences":"","ReasonRejected":"","MemberCategory":"","EngineerVerifiedLeftConn":"False","BarcodeId":"","ManufacturingGUID":"42bbf9cc-52da-4712-a5fc-e37c5a544c14","aess":"False","FabricationComplete":"**NOT SET**","UserComment2":"","UserComment3":"","LoadNumber":"","UserComment1":"","ErectionBolted":"**NOT SET**","RequestVerifyLength":"False","RequestVerifyGrade":"False","Painted":"False","HeatCertNumber":"","Route1Description":"","IsExisting":"No","ReceivedFromApproval":"**NOT SET**","BackCheckedBy":"","BatchNumber":"","CostCodeReference":"","PONumber":"","Piecemark":"B_25","ReleasedForFabrication":"**NOT SET**","MemberDescription":"BEAM","EngineerVerifiedMemberReady":"False","IFCTaskName_2":"","IFCTaskName_1":"","IFCTaskName_4":"","RequestVerifyMemberPosition":"False","IFCTaskName_3":"","Erected":"**NOT SET**","RevisionCheckedBy_3":"","IFCTaskName_5":"","RevisionCheckedBy_2":"","RevisionCheckedBy_1":"","EngineerVerifiedLeftComments":"","RequestVerifyLeftConnMaterial":"False","RequestEngineerVerify":"False","RevisionCheckedDate_3":"**NOT SET**","RevisionCheckedDate_2":"**NOT SET**","RevisionCheckedDate_1":"**NOT SET**","EngineerVerifiedLength":"False","BackCheckedDate":"**NOT SET**","SubmittedForApproval":"**NOT SET**","EngineerVerifiedSpecial":"False","CostCodeDescription":"","IFCStartDate_5":"**NOT SET**","TieForcesLeft":"False","Fireproofed":"False","ErectorAvailable":"False","RequestVerifyRightConnMaterial":"False","DetailCheckedDate":"**NOT SET**","ErectorNonSteelSupported":"False","BeamPent":"False","StockStatus":"","Sequence":"1","RequestVerifyLeftLoad":"False","DetailFinalCheckDate":"**NOT SET**","ErectorMemberPlaced":"**NOT SET**","InstanceStatus":"","EngineerVerifiedRightConn":"False","DateReceived":"**NOT SET**","MemberType":"Beam","ModelCheckDate":"**NOT SET**","ReasonForHold":"","EngineerVerifiedRightComments":"","ReceivedOnJobSite":"**NOT SET**","RequestVerifyRightLoad":"False","CostCodePrice":"0.0","NestStatus":"","DateDue":"**NOT SET**","ShopSequence":"","EngineerVerifiedSectionSize":"False","ActualLength":"144","InputDate":"**NOT SET**","ErectorCity":"Unknown","EngineerVerifiedSpecial_comments":"","Route4Description":"","EngineerVerifiedGrade":"False","RightLocation":"0.0xx144.0xx156.0xx","IFCFinishTime_2":"","IFCFinishTime_1":"","IFCFinishTime_4":"","Route3Description":"","IFCFinishTime_3":"","LoadStatus":"","ErectorLongitude":"","DateModelCompleted":"61299957600000","Grade":"##SEKRIT KODE!!##","IFCFinishTime_5":"","Route2Description":"","RequestVerifyCamber":"False","ProjectedFabricationComplete":"**NOT SET**","DetailedBy":"","DetailFinalCheckBy":"","Description":"W8x35","ProjectedShippedDate":"**NOT SET**","NestName":"","IFCStartDate_2":"**NOT SET**","IFCStartTime_1":"","IFCStartDate_1":"**NOT SET**","IFCStartDate_4":"**NOT SET**","IFCStartDate_3":"**NOT SET**","IFCStartTime_5":"","IFCStartTime_4":"","IFCStartTime_3":"","DateHeld":"**NOT SET**","IFCStartTime_2":"","LeftLocation":"0.0xx0.0xx156.0xx","Job":"Mobile_x_x_x_x_Demo_x_x_x_x_IN_x_x_x_x_2011","SpecialCutWeld":"False","RejectedBy":"","ErectionWelded":"**NOT SET**","RequestVerifyRightConnConfig":"False","Vendor":"","PackageNumber":"","RejectedByErector":"**NOT SET**","ModelCheckedBy":"","ApprovalStatus":"Not reviewed","RequestVerifyLeftConnConfig":"False","ErectorLatitude":"","LotName":"","ActualShipDate":"**NOT SET**","NestId":""}Done followed by a mess of whitespace. Enough that gedit has trouble loading it all. One step forward two steps back. :/
sizeof(int) may not be the same on both devices. So you probably should hardcode something if you want to pass a binary integer. If you evaluate int('\001\002\003\004\005\006\007\010'), you're unlikely to get what you want, and I believe that's close to what you're doing in your Python code. For one thing, the endianness of the two devices might be different, and for another, int() wants to evaluate ASCII or some other encoding, not raw endian-dependent integers. On the python side, you might find this useful: http://stromberg.dnsalias.org/~strombrg/bufsock.html I'm not sure about the out.write() you're using, but at the lower level of send(), there's no guarantee that your entire buffer will be written in a single send() - it's allowed to stop early and just return how much was sent. Hopefully, java protects you from that detail the way bufsock does for python.
Why are you "assuming" that the string has been truncated? print it and see what it actually is. Also, the string that is being sent (as you posted it) is not enclosed in {}, which means it is not proper JSON... I tried to copy/paste it in the interpreter, this raises a ValueError: ValueError: Extra data: line 1 column 17 - line 1 column 3952 (char 17 - 3952) I enclosed it in {} and it worked. You should try to see what the string you are receiving actually is on the python side, and then you can really see what's happening. I assume also, that since you are seeing the "Done" sent, then the content should have been sent completely.