Send SMS with STM32l152 and SIM900 - sms

I send the SMS "Hello World", but on my cellular I get this message ATAT+CMGS="xxxxxx">HelloWorld instead. What can be causing this?
void controlAT()
{
clearString();
wait_ms(100);
SIM900.printf("AT\r");
wait_ms(1000);
if(result=="\r\nOK\r\n") {
pc.printf("\r\n----OK AT----\r\n");
}else {
pc.printf("-- ERROR AT --");
}
pc.printf("%s",result.c_str());
}
/*send SMS */
void sendSMS_Raw()
{
clearString();
SIM900.printf("AT+CMGS=");
SIM900.printf("\"");
SIM900.printf("+xxxxxxxxxxxxx");
SIM900.printf("\"");
SIM900.printf("\r");
SIM900.printf("Hello World");
SIM900.printf("\r");
SIM900.putc(0x1A);
wait_ms(200);
pc.printf("%s",result.c_str());
clearString();
})
/**MAIN**/
int main() {
pc.printf("\r\n GSM 900 TEST\n");
SIM900.attach(&callback_rx);
SIM900.baud(9600);
wait_ms(100);
while(1) {
wait(1.0); // 1 sec
pc.printf("\r\n---MAIN---\n");
controlAT();
sendSMS_Raw();
pc.printf("\r\n---FINE---\n");
wait(2.0); // 1 sec
}
}

the fix it in this metod:
void sendSMS_Raw()
{
pc.printf("\r\n----sendSMS2----\r\n");
clearString();
SIM900.printf("AT+CMGS=");
SIM900.printf("\"");
SIM900.printf("+xxxxxxxxx");
SIM900.printf("\"");
SIM900.printf("\r");
wait_ms(200); // this create the problem
SIM900.printf("Hello");
SIM900.printf("\r");
SIM900.putc(0x1A);
wait_ms(200);
pc.printf("%s",result.c_str());
clearString();
}
thank for all.

Related

How do I get LocationManager.addNmeaListener() to work?

Here are the relevant parts of my code:-
public class MainActivity extends Activity
implements SensorEventListener, OnNmeaMessageListener {
private LocationManager m_locationManager;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ac = this;
m_locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
}
...
protected void onResume() {
...
if (m_locationManager != null) {
m_gpsSensor = new SensorView(this);
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
m_locationManager.addNmeaListener(getMainExecutor(), this);
} else {
// no-op in later versions
m_locationManager.addNmeaListener(this);
}
m_gpsSensor.lineBreak("gps: ", "no messages yet");
} catch (Exception ignore) {
m_gpsSensor.lineBreak("gps: ", getString(R.string.permissiondenied));
}
topLayout.addView(m_gpsSensor);
}
}
#Override
public void onNmeaMessage(String message, long timestamp) {
long nanos = timestamp * 1000000;
if (nanos > m_gpsSensor.lastNanos + UPDATE_NANOS) {
m_gpsSensor.lastNanos = nanos;
m_gpsSensor.lineBreak("gps: ", message);
}
}
}
onNmeaMessage is never called (lastNanos is initialised to zero) and m_gpsSensor (a subclass of View) displays "no messages yet". My device does have GPS, and the app has permission to access it (otherwise it would display "Permission denied"), and GPS does work, because it can see satellites and get a fix with Satstat
I tried
addNmeaListener (OnNmeaMessageListener listener, Handler handler)
which doesn't work either. m_locationManager isn't null, because in that case it wouldn't display anything at all.
The device is a Samsung Galaxy S21 Ultra 5G running Android 12.
What am I doing wrong?
Apparently addNmeaListener doesn't start the GPS, and there doesn't seem to be an explicit call to do so. You have to call one of the requestLocationUpdates variants.

Akka.Net BecomeStacked/UnbecomeStacked behavior issue

I have a problem with the behavior switch model.
I have a simple receive actor with 2 behaviors: Ready & DoJob.
The Ready one contains a message handler plus one instruction I need to be evaluated at each behavior switch (cpt++).
Below is the code of the actor:
public class BecomeUnbecome : ReceiveActor
{
private int cpt=0;
public BecomeUnbecome()
{
this.Become(this.Ready);
}
public void Ready()
{
cpt++;
Receive<BeginWork>(msg =>
{
Console.WriteLine($"Go and work!");
BecomeStacked(this.DoJob);
});
}
public void DoJob()
{
Receive<Work>(msg =>
{
Console.WriteLine("Start working...");
Console.WriteLine($"Counter: {cpt}\nWork done\n");
UnbecomeStacked();
});
}
}
The main code is:
int counter = 0;
while (counter < 10)
{
actor.Tell(new BeginWork());
actor.Tell(new Work());
counter++;
}
The program execution shows cpt++ in Ready() is evaluated once next to the call to Become in the constructor.
I cannot find any reasonable workaround to that.
Does anyone have any idea ?

can persistent communication be used in the for loop?

I want to change MPI_Isend() and MPI_Irecv() to persist communication to reduce time of my parallel program.
But variables in communication process will be changed during the iteration, so I alter my code in the communicaiton function as follows.
My questions are:
Is it persistent communication after modification?
If it is not persistent communication after modification,why did the time of program go down while the result of computation is correct?
int main()
{
for()
{
//calculation process 1 will change value of q1,q2,b1,b2,b3,b4
....
//communication process
void comm()
{
/*if(rightBoundary==virtualWall)
{
rightProcessNum=processNum+decompositionY*decompositionZ;
for(int k=1;k<nz+1;k++)
for(int j=1;j<ny+1;j++)
{
MPI_Isend(&q1[n][k][j][nx],1,MPI_DOUBLE,rightProcessNum,20,MPI_COMM_WORLD,&req1[0]);
MPI_Isend(&b1 [k][j][nx],1,MPI_DOUBLE,rightProcessNum,21,MPI_COMM_WORLD,&req1[1]);
MPI_Isend(&b2 [k][j][nx],1,MPI_DOUBLE,rightProcessNum,22,MPI_COMM_WORLD,&req1[2]);
MPI_Isend(&b2 [k][j][nx],1,MPI_DOUBLE,rightProcessNum,23,MPI_COMM_WORLD,&req1[3]);
MPI_Isend(&b4 [k][j][nx],1,MPI_DOUBLE,rightProcessNum,24,MPI_COMM_WORLD,&req1[4]);
MPI_Isend(&q2[n][k][j][nx],1,MPI_DOUBLE,rightProcessNum,25,MPI_COMM_WORLD,&req1[5]);
MPI_Waitall(6,req1,sta1);
}
}
if(leftBoundary==virtualWall)
{
leftProcessNum=processNum-decompositionY*decompositionZ;
for(int k=1;k<nz+1;k++)
for(int j=1;j<ny+1;j++)
{
MPI_Irecv(&q1[n][k][j][0],1,MPI_DOUBLE,leftProcessNum,20,MPI_COMM_WORLD,&req2[0]);
MPI_Irecv(&b1 [k][j][0],1,MPI_DOUBLE,leftProcessNum,21,MPI_COMM_WORLD,&req2[1]);
MPI_Irecv(&b2 [k][j][0],1,MPI_DOUBLE,leftProcessNum,22,MPI_COMM_WORLD,&req2[2]);
MPI_Irecv(&b3 [k][j][0],1,MPI_DOUBLE,leftProcessNum,23,MPI_COMM_WORLD,&req2[3]);
MPI_Irecv(&b4 [k][j][0],1,MPI_DOUBLE,leftProcessNum,24,MPI_COMM_WORLD,&req2[4]);
MPI_Irecv(&b5[n][k][j][0],1,MPI_DOUBLE,leftProcessNum,25,MPI_COMM_WORLD,&req2[5]);
MPI_Waitall(6,req2,sta2);
}
}*/
if(rightBoundary==virtualWall)
{
rightProcessNum=processNum+decompositionY*decompositionZ;
for(int k=1;k<nz+1;k++)
{
for(int j=1;j<ny+1;j++)
{
MPI_Send_init(&q1[n][k][j][nx],1,MPI_DOUBLE,rightProcessNum,20,MPI_COMM_WORLD,&req1[0]);
MPI_Send_init(&b1 [k][j][nx],1,MPI_DOUBLE,rightProcessNum,21,MPI_COMM_WORLD,&req1[1]);
MPI_Send_init(&b2 [k][j][nx],1,MPI_DOUBLE,rightProcessNum,22,MPI_COMM_WORLD,&req1[2]);
MPI_Send_init(&b3 [k][j][nx],1,MPI_DOUBLE,rightProcessNum,23,MPI_COMM_WORLD,&req1[3]);
MPI_Send_init(&b4 [k][j][nx],1,MPI_DOUBLE,rightProcessNum,24,MPI_COMM_WORLD,&req1[4]);
MPI_Send_init(&q2[n][k][j][nx],1,MPI_DOUBLE,rightProcessNum,25,MPI_COMM_WORLD,&req1[5]);
MPI_Startall(6,req1);
}
}
MPI_Waitall(6,req1,sta1);
MPI_Request_free(req1);
}
if(leftBoundary==virtualWall)
{
leftProcessNum=processNum-decompositionY*decompositionZ;
for(int k=1;k<nz+1;k++)
{
for(int j=1;j<ny+1;j++)
{
MPI_Recv_init(&q1[n][k][j][0],1,MPI_DOUBLE,leftProcessNum,20,MPI_COMM_WORLD,&req2[0]);
MPI_Recv_init(&b1 [k][j][0],1,MPI_DOUBLE,leftProcessNum,21,MPI_COMM_WORLD,&req2[1]);
MPI_Recv_init(&b2 [k][j][0],1,MPI_DOUBLE,leftProcessNum,22,MPI_COMM_WORLD,&req2[2]);
MPI_Recv_init(&b3 [k][j][0],1,MPI_DOUBLE,leftProcessNum,23,MPI_COMM_WORLD,&req2[3]);
MPI_Recv_init(&b4 [k][j][0],1,MPI_DOUBLE,leftProcessNum,24,MPI_COMM_WORLD,&req2[4]);
MPI_Recv_init(&q2[n][k][j][0],1,MPI_DOUBLE,leftProcessNum,25,MPI_COMM_WORLD,&req2[5]);
MPI_Startall(6,req2);
}
}
MPI_Waitall(6,req2,sta2);
MPI_Request_free(req2);
}
}
//calculation process 2
....
}
}
I appreciate your time and suggestion in this problem.

Custom Event Handling in GStreamer 1.0

I am having a hard time wrapping my head around GStreamer event sending and handling. I understand the process, but can not achieve my desired outcome. I am developing a series of GStreamer plugins in tandem with a GStreamer main application. I have 3 plugins my_src which inherits from GstPushSrc, my_transform which inherits from GstBaseTransform and my_sink which inherits from GstBaseSink, and a main application my_app.
I am trying to send a custom event from my_app to all elements in the pipeline telling them to reconfigure the processing parameters. This is different from GST_EVENT_RECONFIGURE because it does not involve any renegotiation of caps. I am sending the event from my_app with the following:
// my_app.c
GstStructure *reconfigureStructure = gst_structure_new("reconfigure", NULL);
GstEvent *reconfigureEvent = gst_event_new_custom(GST_EVENT_CUSTOM_DOWNSTREAM,
reconfigureStructure);
gst_element_send_event(pipeline, reconfigureEvent);
I have overridden the GstBaseSrc event() method as follows:
// my_src.c
static gboolean my_src_event(GstBaseSrc *bs, GstEvent *event);
static void
my_src_class_init(MySrcClass *msc)
{
GstBaseSrcClass *bsc = GST_BASE_SRC_CLASS(msc);
bsc->event = my_src_event;
}
static gboolean
my_src_event(GstBaseSrc *bs, GstEvent *event)
{
switch (GST_EVENT_TYPE(event)) {
case GST_EVENT_CUSTOM_DOWNSTREAM: {
const GstStructure *structure = gst_event_get_structure(event);
if (gst_structure_has_name(structure, "reconfigure")) {
g_print("MY SRC RECONFIGURE\n");
// do reconfigure things
}
break;
}
}
return GST_BASE_SRC_CLASS(parent_class)->event(bs, event);
}
Similarly, I have overridden the GstBaseSink event handler as follows:
// my_sink.c
static gboolean my_sink_event(GstBaseSink *bs, GstEvent *event);
static void
my_sink_class_init(MySinkClass *msc)
{
GstBaseSinkClass *bsc = GST_BASE_SINK_CLASS(msc);
bsc->event = my_sink_event;
}
static gboolean
my_sink_event(GstBaseSink *bs, GstEvent *event)
{
switch (GST_EVENT_TYPE(event)) {
case GST_EVENT_CUSTOM_DOWNSTREAM: {
const GstStructure *structure = gst_event_get_structure(event);
if (gst_structure_has_name(structure, "reconfigure")) {
g_print("MY SINK RECONFIGURE\n");
// do reconfigure things
}
break;
}
}
return GST_BASE_SINK_CLASS(parent_class)->event(bs, event);
}
Lastly, I have overridden the GstBaseTransform sink_event() method as follows:
// my_transform.c
static gboolean my_transform_sink_event(GstBaseTransform *bt, GstEvent *event);
static void
my_transform_class_init(MyTransformClass *mtc)
{
GstBaseTransformClass *btc = GST_BASE_TRANDFORM_CLASS(mtc);
btc->sink_event = my_transform_sink_event;
}
static gboolean
my_transform_sink_event(GstBaseTransfor *bt, GstEvent *event)
{
switch (GST_EVENT_TYPE(event)) {
case GST_EVENT_CUSTOM_DOWNSTREAM: {
const GstStructure *structure = gst_event_get_structure(event);
if (gst_structure_has_name(structure, "reconfigure")) {
g_print("MY TRANSFORM RECONFIGURE\n");
// do reconfigure things
}
break;
}
}
return GST_BASE_TRANSFORM_CLASS(parent_class)->sink_event(bt, event);
}
When I run my_app I would expect the output to be:
MY SRC RECONFIGURE
MY TRANSFORM RECONFIGURE
MY SINK RECONFIGURE
However, I am only getting:
MY SINK RECONFIGURE
Any ideas what I am doing wrong here?

Pebble AppMessage crash when sending string containing accents from the phone to the watch

I'm building an API based application. I use the Pebble.SendAppMessage function to send data from the API to the watch. Each time I try to send data containing accentued characters and log them, the console print this following empty message:
[xx:xx:xx] javascript>
and no more interaction between the phone and the watch will work.
I first tried to encode each API data to UTF8 encoding but the crash still appears.
Can we send strings containing accents using the Pebble.SendAppMessage function? What exactly did I miss?
C code :
#include <pebble.h>
static Window *window;
static TextLayer *text_layer;
static void message_provider(DictionaryIterator* iterator, void* context) {
Tuple* tuple = dict_find(iterator, 0);
text_layer_set_text(text_layer, tuple->value->cstring);
}
static void window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window);
GRect bounds = layer_get_bounds(window_layer);
text_layer = text_layer_create((GRect) { .origin = { 0, 72 }, .size = { bounds.size.w, 20 } });
text_layer_set_text(text_layer, "Loading...");
text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
layer_add_child(window_layer, text_layer_get_layer(text_layer));
}
static void window_unload(Window *window) {
text_layer_destroy(text_layer);
}
static void init(void) {
window = window_create();
window_set_window_handlers(window, (WindowHandlers) {
.load = window_load,
.unload = window_unload,
});
const bool animated = true;
window_stack_push(window, animated);
app_message_register_inbox_received(message_provider);
app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
}
static void deinit(void) {
window_destroy(window);
}
int main(void) {
init();
app_event_loop();
deinit();
}
JS code :
Pebble.addEventListener("ready", function() {
Pebble.sendAppMessage({"dummy" : "Gérard example is always the best."}, function() {
console.log("message sent successfully !");
}, function() {
console.log("Cannot send message with accent.");
});
});

Resources