AT command sent SMS received as Flash SMS (Class 0 SMS) - wpf

I used this link to send SMS with AT command in WPF.
But when I send SMS with CMGS command, the receiver get the SMS as Flash SMS not usual SMS. My code is as below:
//Check if modem allows you to send and receive SMS messages using AT commands, without the need to decode the binairy PDU field of the SMS first
rval = sp.SendCommand("AT+CMGF=1");
//set Text mode parameters
rval = sp.SendCommand("AT+CSMP=17,167,0,16");
string phonenumber = "xxxxxxxxxxx";
string Message = "test";
rval = sp.SendCommand("AT+CMGS=\"" + phonenumber + "\"");
if (rval.Equals("\r\n> "))
{
rval = sp.SendCommand(Message + char.ConvertFromUtf32(26) );
}
and my SendCommand is as below
public string SendCommand(String commandText)
{
if (!serialPort.IsOpen)
{
try
{
serialPort.Open();
}
catch (Exception ex)
{
LogEvents.InLogFile(ex.Message);
throw new Exception("COM port is busy");
}
}
try
{
serialPort.DiscardOutBuffer();
serialPort.DiscardInBuffer();
buff = "";
serialPort.Write(commandText + "\r");
Thread.Sleep(serialPort.ReadTimeout);
return buff;
}
catch (Exception)
{
throw new Exception("Error connection");
}
}
Can any one help me?
My other references:
developershome,
Sayeda Anila Nusrat

The fourth parameter in AT+CSMP sets the coding scheme, i don't remember in which document i've found the coding of this byte but bit 7 sets whether the message should be discarded after showing it class 0 or stored
You should set this bit to 1 to make it storable, so changing
rval = sp.SendCommand("AT+CSMP=17,167,0,16");
to
rval = sp.SendCommand("AT+CSMP=17,167,0,144");
should do the work

Bit 0 (i.e., the least significant bit) of the fourth parameter of the AT+CSMP command is a flag for whether the SMS will be flashed (when 0) or saved (when 1).
Simply put: An even number for 4th parameter will NOT save the message, while an odd number will.

Change AT+CSMP=17,167,0,16 to AT+CSMP=17,167,0,0.

Related

Spring LDAP AD paging support not working - LDAP: error code 12 - 00000057: LdapErr: DSID-0C09079A

When trying to run the code above I'm getting javax.naming.OperationNotSupportedException with the message:
[LDAP: error code 12 - 00000057: LdapErr: DSID-0C09079A, comment: Error processing control, data 0, v2580].
The first page is successfully retrieved and the exception is thrown only at second loop iteration.
public void pagedResults() {
PagedResultsCookie cookie = null;
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
int page = 1;
do {
logger.info("Starting Page: " + page);
PagedResultsDirContextProcessor processor = new PagedResultsDirContextProcessor(20, cookie);
List<String> lastNames = ldapTemplate.search("", initialFilter.encode(), searchControls, UserMapper.USER_MAPPER_VNT, processor);
for (String l : lastNames) {
logger.info(l);
}
cookie = processor.getCookie();
page = page + 1;
} while (null != cookie.getCookie());
}
However, when I remove Spring LDAP using pure implementation as above, it works!
try {
LdapContext ctx = new InitialLdapContext(env, null);
// Activate paged results
int pageSize = 5;
byte[] cookie = null;
ctx.setRequestControls(new Control[] { new PagedResultsControl(pageSize, Control.CRITICAL) });
int total;
do {
/* perform the search */
NamingEnumeration results = ctx .search("",
"(&(objectCategory=person)(objectClass=user)(SAMAccountName=vnt*))",
searchCtls);
/* for each entry print out name + all attrs and values */
while (results != null && results.hasMore()) {
SearchResult entry = (SearchResult) results.next();
System.out.println(entry.getName());
}
// Examine the paged results control response
Control[] controls = ctx.getResponseControls();
if (controls != null) {
for (int i = 0; i < controls.length; i++) {
if (controls[i] instanceof PagedResultsResponseControl) {
PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i];
total = prrc.getResultSize();
if (total != 0) {
System.out.println("***************** END-OF-PAGE "
+ "(total : " + total
+ ") *****************\n");
} else {
System.out.println("***************** END-OF-PAGE "
+ "(total: unknown) ***************\n");
}
cookie = prrc.getCookie();
}
}
} else {
System.out.println("No controls were sent from the server");
}
// Re-activate paged results
ctx.setRequestControls(new Control[] { new PagedResultsControl(
pageSize, cookie, Control.CRITICAL) });
} while (cookie != null);
ctx.close();
} catch (NamingException e) {
System.err.println("PagedSearch failed.");
e.printStackTrace();
} catch (IOException ie) {
System.err.println("PagedSearch failed.");
ie.printStackTrace();
}
Any hints?
The bad thing about LDAP paged results is that they only work if the same underlying connection is used for all requests. The internals of Spring LDAP get a new connection for each LdapTemplate operation, unless you use the transactional support.
The easiest way to make sure the same connection will be used for a sequence of LDapTemplate operations is to use the transaction support, i.e. configure transactions for Spring LDAP and wrap the target method with a Transactional annotation.
I managed to make my example above work using SingleContextSource.doWithSingleContext approach.
However my scenario is different, my app is service oriented and the paged results as well as the cookie should be sent to an external client so that he decides to request next pages or not.
So as far as I can tell, spring-ldap does not support such case. I must use pure implementation so that I can keep track of the underlying connection during requests. Transaction support could help as well as SingleContextSource, but not among different requests.
#marthursson
Is there any plan in spring ldap to such support in the future?
I found I could use your first example (Spring) as long as I set the ignorePartialResultException property to true in my ldapTemplate configuration and put the #Transactional on my method as suggested.
you can replace ldapTemplate DirContext like this
ldapTemplate.setContextSource(new SingleContextSource(ldapContextSource().getReadWriteContext()));

The message content in a line is becomes 2 lines when reading from InputStream

I am using android JavaMail.
I would like to parse the inputStream of the content myself. So I use
InputStreamReader reader = new InputStreamReader(messages[i].getInputStream());
int value;
StringBuilder out = new StringBuilder();
while((value = reader.read()) != -1) {
out.append((char) value);
}
reader.close();
Log.i(TAG, out.toString());
The original string content is :
<body lang=3D"ZH-TW" link=3D"#0563C1" vlink=3D"#954F72" style=3D"text-justify-trim:punctuation">
But when in the printout result is
<body lang=3D"ZH-TW" link=3D"#0563C1" vlink=3D"#954F72" style=3D"text-justi=
fy-trim:punctuation">
There is extra "=" in the line and it breaks into two line.
"=" seems indicate that the line is not ended yet. How did it happen?
If the line actually ends with =, then how can we differentiate?
Bill, I can work with work around problems with broken IMAP servers
according to the https://www.rfc-editor.org/rfc/rfc3501#section-6.4.5
Arguments: sequence set
message data item names or macro
so it seems that we can fetch with UID specified.
When i am using javamail, even though have the API fetch the message by UID.
javax.mail.Message[] messages = folder.getMessagesByUID(localFolderObject.getUIDNext(),
serverFolderObject.getUIDNext());
for (int i = 0; i < messages.length; ++i) {
// Get the message object from the folder
MimeMessage msg = (MimeMessage) messages[i];
// Copy the message by writing into an byte array.
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
msg.writeTo(bos);
bos.close();
Log.i(TAG, bos.toString());
}
catch (IOException e) {
e.printStackTrace();
}
}
the fetch issue as
A38 FETCH 1 (BODY[])
1 is message sequence number, not the UID.
The server wants us to fetch with
A5 UID FETCH 291 (BODY[])
Is there any API "UID Fetch" command for getting the message https://www.rfc-editor.org/rfc/rfc3501#section-6.4.8?
I won't retreive all the messages every time. will keep the previous last NextUID and next time retrieve will start from previous save next UID.
Due to fetch by sequence number, the server always return the first sequnce message instead of the one i want.

apache pop3 bufferedreader lines end with = (equals)

I try to receive some messages from a POP3 mail server using the apache POP3 mail client.
I use a BufferedReader to get messages from my POP3 mail server (retreiveMessage(id)). I have some mails with long lines and I read them with a loop like below. My lines are truncated into several lines ending with the equal sign (=), each line with 76 chars plus the =.
import org.apache.commons.net.pop3.POP3Client;
import org.apache.commons.net.pop3.POP3MessageInfo;
...
POP3Client pop = new POP3Client();
pop.setSocketFactory(SSLSocketFactory.getDefault());
pop.setDefaultTimeout(60000);
pop.connect(MAIL_SEREVR, PORT);
String username = USERNAME;
String password = PASSWORD;
isVerified = pop.login(username, password);
POP3MessageInfo[] messages = pop.listMessages();
for (POP3MessageInfo msginfo : messages) {
Date timestamp = new Date();
BufferedReader reader = (BufferedReader) pop
.retrieveMessage(msginfo.number);
if (reader == null) {
System.err.println("Could not retrieve message header.");
pop.disconnect();
System.exit(1);
}
try {
printMessageInfo(reader, msginfo.number, timestamp);
} catch (Exception e) {
e.printStackTrace();
}
pop.deleteMessage(msginfo.number);
}
pop.logout();
pop.disconnect();
So, I print the messages and since a word is too long, it is truncated like this:
this is a short line, it is OK
andThisIsALongLineWithMoreThan76CharactersButThisIsEmpiricalIJustSeeThatThe=
LineIsTruncatedAtThe76thCHAR
is this a normal behavior? can someone help me?
thanks
It doesn't sound like you're using JavaMail. It you aren't, use it, it will make life easier for you. If you are, explain in more detail what you're doing.

Arduino: Converting a client.read()

I'm trying to check the number of unread Mails with an Arduino+Ethernet Shield, sending two IMAP-requests.
With client.read(server_answer), I store it into a char.
When I send it to serial with Serial.print(server_answer), I get the following:
* OK IMAP server ready H migmx111 92345
0 OK LOGIN completed
* STATUS INBOX (UNSEEN 1)
0 OK STATUS completed
* STATUS INBOX (MESSAGES 1917)
0 OK STATUS completed
* BYE Server logging out
0 OK LOGOUT completed
Now my question: How can I extract the two numbers (total count of mails and unread mails, in the example 1 unread and 1917 total count)?
How can I get them in two different strings?
I want to display the numbers with some some text ("You have [number] new mails!") on a LCD.
If it helps, here's interesting part of my code:
void loop()
{
updateClient();
checkAvail();
}
void updateClient()
{
if ((millis() - updateTimer) > 10000)
{
Ethernet.begin(mac, ip);
// Serial.println("connecting...");
delay(1000);
if (client.connect())
{
//Serial.println("connected");
client.println("0 login myusername mypasswd");
client.println("0 STATUS INBOX (UNSEEN)");
client.println("0 STATUS INBOX (MESSAGES)");
client.println("0 logout");
clientConnected = true;
}
else
{
Serial.println("connection failed");
}
updateTimer = millis();
}
}
void checkAvail()
{
if (clientConnected)
{
if (client.available())
{
server_answer = client.read();
Serial.print(server_answer);
}
if (!client.connected())
{
Serial.println();
// Serial.println("disconnecting.");
client.stop();
clientConnected = false;
}
}
}
Without writing your code for you, you need to break the incoming data up into chunks using strtok_r(). Looking at your code above calling strtok_r() with '(' as a delimiter then again with a space as a delimiter and then again with ')' should get you to the begining of your first number. From there atoi() will convert it to an interger. Repeating the process should get you to the second value as well.
Take a crack at this and post your code if you have any more problems.

Database problem: how to diagnose and fix the problem?

I created an application which stores values into the database and retrieves the stored data. While running an application in run mode everything seems to work fine (the values are stored and retrieved successfully) but when I run in the debug mode the process throws IllegalStateException and so far haven't found a cause.
The method which retrieves an object Recording is the following:
public Recording getRecording(String filename) {
Recording recording = null;
String where = RECORDING_FILENAME + "='" + filename + "'";
Log.v(TAG, "retrieving recording: filename = " + filename);
try {
cursor = db.query(DATABASE_TABLE_RECORDINGS, new String[]{RECORDING_FILENAME, RECORDING_TITLE, RECORDING_TAGS, RECORDING_PRIVACY_LEVEL, RECORDING_LOCATION, RECORDING_GEO_TAGS, RECORDING_GEO_TAGGING_ENABLED, RECORDING_TIME_SECONDS, RECORDING_SELECTED_COMMUNITY}, where, null, null, null, null);
if (cursor.getCount() > 0) {
cursor.moveToFirst();
//String filename = c.getString(0);
String title = cursor.getString(1);
String tags = cursor.getString(2);
int privacyLevel = cursor.getInt(3);
String location = cursor.getString(4);
String geoTags = cursor.getString(5);
int iGeoTaggingEnabled = cursor.getInt(6);
String recordingTime = cursor.getString(7);
String communityID = cursor.getString(8);
cursor.close();
recording = new Recording(filename, title, tags, privacyLevel, location, geoTags, iGeoTaggingEnabled, recordingTime, communityID);
}
}
catch (SQLException e) {
String msg = e.getMessage();
Log.w(TAG, msg);
recording = null;
}
return recording;
}
and it is called from another class (Settings):
private Recording getRecording(String filename) {
dbAdapter = dbAdapter.open();
Recording recording = dbAdapter.getRecording(filename);
dbAdapter.close();
return recording;
}
While running through the code above everything works fine but then I notice an exception in another thread:
alt text http://img509.imageshack.us/img509/862/illegalstateexception.jpg
and don't know neither what is the possible cause of this exception nor how to debug the code from that thread to diagnose the cause.
I would be very thankful if anyone knew what is the possible issue here.
Thank you!
Looks like that cursor.close() is inside an "if" - that's when SQLiteCursor.finalize() will throw an IllegalStateException (I googled for it). You migh be getting an empty recordset, for instance, if some other process/thread didn't have the time to commit.
Close it always, even if it's result set is empty.
I'd also advice you to access fields by names, not indices, for future compatibility. And do both close()s in finally{} blocks.

Resources