As previously mentioned, we can provide authentication also by checking the sender.
In the same way as, in previous examples, we checked whether the sender of an incoming call was authorized, you can do the same operation with SMS sender.
sms.GetAuthorizedSMS((int)pos,number,message,180,8,10);
Saving the trusted contacts on the within a specific range of the SIM will be enough: we just need to check what’s returned by the function in which we pass the range using the last two parameters.
In this case the authorized number is saved between position 8 and position 10 (both included) of the SIM.
if(stat==GETSMS_AUTH_SMS){
Thanks to the previous condition we will enter the routine associated with the condition in which the SMS is received from a trusted number.
Differently from the previous case, in this example we will analyze a string containing the logic states (0 or 1) that must be set on the digital outputs (for example: “LEDCONF0000″ or “LEDCONF1001″ and so on.)
Using the substrings search function we will identify the command for the allocation of the states and then we will move forward analyzing it character by character and then setting the appropriate status to its output.
In this example, the “LEDCONF0000″ string, sent to turn off all outputs, is composed of the first part (LEDCONF) that relates to the command type (in fact we could send different commands within a single message) and by a following part containining 0000 as the states to be set on the outputs ranging from 9 to 12.
Recalling that the search function, if successful, returns a pointer to the first character of the substring, you will need to move forward of a number of characters that is sufficient to reach the first value containing the information on the first output.
We’ll do this thanks to the strlen(char* string) function that gives back an integer with the length of the string passed as a parameter.
Then we translate the pointer of a number of characters that is equal to the length of the command:
p=p+strlen(“LEDCONF”);
In this way the p pointer will refer to the first numeric character.
will be sufficient to check if this is equal to 1 or 0 to activate or not the output to it associated with it.
if(p[0]==’1′)
For your convenience we will put everything in a loop equipped with some diagnostic messages (not strictly necessary) sent to the hardware serial port.
As we did before, at the end of the cycle we first delete the SMS and then add a a few seconds delay to avoid making continuous queries to the shield.
ตามที่กล่าวไว้ก่อนหน้านี้ เราสามารถให้บริการการตรวจสอบโดยการตรวจสอบผู้ส่ง
ไปในทางเดียวกัน เช่น ในตัวอย่างก่อนหน้านี้ เราตรวจสอบว่าผู้ส่งมีสายเรียกเข้ามา ได้รับอนุญาต คุณสามารถทำเช่นเดียวกันกับ SMS ผู้ส่ง SMS ( .
. getauthorizedsms ( INT ) POS , หมายเลข , ข้อความ , 180,8,10 ) ;
ประหยัดเชื่อถือได้ติดต่อกับภายในช่วงที่เฉพาะเจาะจงของซิมการ์ดจะเพียงพอ :เราต้องดูอะไรที่ส่งกลับโดยฟังก์ชันที่เราผ่านช่วงที่ใช้ล่าสุดสองตัว
ในกรณีนี้อนุญาตเลขที่ถูกบันทึกไว้ระหว่างตำแหน่งและตำแหน่ง 10 ( รวม ) ของซิม
ถ้า stat = = getsms_auth_sms ) {
ขอบคุณสำหรับภาพก่อนหน้า เราจะเข้าประจำที่เกี่ยวข้องกับเงื่อนไขที่ได้รับ SMS จากหมายเลขไว้ใจ
แตกต่างจากกรณีก่อนหน้านี้ ในตัวอย่างนี้เราจะวิเคราะห์สตริงที่มีตรรกะ สหรัฐอเมริกา ( 0 หรือ 1 ) ที่ต้องตั้งค่าเอาท์พุทดิจิตอล ( ตัวอย่างเช่น : " ledconf0000 เพลงหรือ " ledconf1001 เพลงและอื่น ๆ )
การใช้ฟังก์ชันการค้นหาสตริงย่อยเราจะระบุคำสั่งสำหรับการจัดสรรของอเมริกา และเราก็จะเดินหน้าตรวจสอบมันตัวละครโดยตัวละครแล้วการตั้งค่าสถานะที่เหมาะสมกับผลผลิตของตน .
ในตัวอย่างนี้ สตริง " ledconf0000 เพลง ส่ง ปิดทั้งหมด ผลผลิตประกอบด้วย ส่วนแรก ( ledconf ) ที่เกี่ยวข้องกับชนิดของคำสั่ง ( ในความเป็นจริงเราสามารถส่งคำสั่งต่างๆ ในข้อความเดียว ) และโดยต่อไปนี้เป็นส่วนหนึ่ง containining 0000 อเมริกาจะถูกตั้งค่าไว้ในผลตั้งแต่ 9 ถึง 12
เรียกว่าฟังก์ชันการค้นหา หากสำเร็จ ผลตอบแทนตัวชี้กับตัวอักษรตัวแรกของข้อความ ,คุณจะต้องย้ายไปข้างหน้าของจำนวนของอักขระที่เพียงพอที่จะเข้าถึงแรกมูลค่าที่มีข้อมูลเกี่ยวกับผลผลิตแรก
เราทำนี้เพื่อขอบคุณ strlen ( สตริง char * ) ฟังก์ชันที่ช่วยให้กลับมาจำนวนเต็มกับความยาวของสตริงที่ผ่านเป็นพารามิเตอร์
แล้วเราแปล ตัวชี้ของจำนวนของอักขระที่เท่ากับความยาวของคำสั่ง :
P = ( p strlen " ledconf
" ) ; ในวิธีนี้ P ตัวชี้จะอ้างถึงตัวเลขแรก
จะเพียงพอที่จะตรวจสอบว่ามันเท่ากับ 1 หรือ 0 เพื่อเปิดใช้งาน หรือ ไม่ ออก มันเกี่ยวข้องกับมัน
ถ้า ( p [ 0 ] = = ' 1 ดูแล )
เพื่อความสะดวกของคุณ เราจะใส่ทุกอย่างในห่วง พร้อมบางวินิจฉัยข้อความ ( ไม่ใช่เรื่องจำเป็น ) ส่งไปยังฮาร์ดแวร์พอร์ตอนุกรม .
เหมือนที่เราทำก่อนที่จุดสิ้นสุดของรอบแรกที่เราลบ SMS แล้วเพิ่มไม่กี่วินาทีหน่วงเวลาเพื่อหลีกเลี่ยงการสอบถามอย่างต่อเนื่องกับโล่
การแปล กรุณารอสักครู่..
