我正在尝试通过SIM800 GSM模块从Arduino发送短信。消息到达给定的数字但不是正确的格式。 它显示"不支持消息格式"。
我在这里包含我的代码,非常感谢快速回复。
#include <SoftwareSerial.h>
SoftwareSerial GPRS(11, 12); //11 = TX, 12 = RX
unsigned char buffer[64]; //port
int count=0;
int i = 0; //if i = 0, send SMS.
void setup() {
GPRS.begin(9600); // the GPRS baud rate
Serial.begin(9600); // the Serial port of Arduino baud rate.
Serial.print("I'm ready");
Serial.print("Hello?");
}
void loop() {
if (GPRS.available()) {
// if date is coming from softwareserial port ==> data is coming from GPRS shield
while(GPRS.available()) {
// reading data into char array
buffer[count++]=GPRS.read();
// writing data into array
if(count == 64)
break;
}
Serial.write(buffer,count);
// if no data transmission ends, write buffer to hardware serial port
clearBufferArray();
// call clearBufferArray function to clear the stored data from the array
count = 0; // set counter of while loop to zero
}
if (Serial.available())
// if data is available on hardwareserial port ==> data is coming from PC or notebook
GPRS.write(Serial.read()); // write it to the GPRS shield
if(i == 0) {
GPRS.write("AT+CMGF=1\r"); //sending SMS in text mode
delay(1000);
Serial.println("AT+CMGF=1\r");
GPRS.write("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // phone number
delay(1000);
Serial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r");
GPRS.write("Hello how are you?\r"); // message
delay(1000);
Serial.println("Hello how are you?\r");
delay(1000);
GPRS.write(0x1A);
//send a Ctrl+Z (end of the message)
delay(1000);
Serial.println("SMS sent successfully");
i++;
}
}
void clearBufferArray(){
// function to clear buffer array
for (int i=0; i<count;i++){
buffer[i]='\0';
// clear all index of array with command NULL
}
}
答案 0 :(得分:1)
简单的方法是通过转到Arduino IDE添加grps库arduino - &gt; Sketch-&gt; Library-&gt;管理库 - 然后输入gprs你会得到库并安装它 试试这个示例代码进行测试,
#include <gprs.h>
#include <SoftwareSerial.h>
GPRS gprs;
void setup() {
Serial.begin(9600);
while(!Serial);
gprs.preInit();
delay(5000); //wait for 5 seconds
while(0 != gprs.init()) {
delay(1000);
Serial.print("Not connected,try again\r\n");
}
Serial.println("Sending SMS");
gprs.sendSMS("844******8","Testing the Module"); //Enter your phone number
and text
}
void loop() {
//If you want the to send the Text continuously then add the code here
}
答案 1 :(得分:0)
尝试将调制解调器字符集设置为&#39; GSM&#39;通过发送以下AT命令:AT + CSCS =“GSM”到调制解调器。以下是添加此命令后代码的外观:
@Override
public boolean zoomTo(CameraSession session,
int zoomLevel) {
final Session s=(Session)session;
final Descriptor descriptor=(Descriptor)session.getDescriptor();
if (s.previewRequest!=null) {
try {
final CameraCharacteristics cc=
mgr.getCameraCharacteristics(descriptor.cameraId);
final float maxZoom=
cc.get(
CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
// if <=1, zoom not possible, so eat the the event
if (maxZoom>1.0f) {
float zoomTo=1.0f+((float)zoomLevel*(maxZoom-1.0f)/100.0f);
Rect zoomRect=cropRegionForZoom(cc, zoomTo);
s.previewRequestBuilder
.set(CaptureRequest.SCALER_CROP_REGION, zoomRect);
s.setZoomRect(zoomRect);
s.previewRequest=s.previewRequestBuilder.build();
s.captureSession.setRepeatingRequest(s.previewRequest, null, handler);
}
}
catch (CameraAccessException e) {
getBus().post(new DeepImpactEvent(e));
}
}
return(false);
}