نمایش نتایج: از 1 به 6 از 6

موضوع: جی اس ام

  1. #1
    Member
    تاریخ عضویت
    May 2016
    نوشته ها
    94

    جی اس ام

    سلام من می خوام وقتی که توسط موبایل به سیم یک پیام ارسال میشه وقتی که سیم پیام را دریافت کرد و درست بود یک ملودی پخش شود می خواستم بدونم که ایا کد مربوط به receive sms در example های اردینو برای این کار خوب است ??
    و اگر خوب است در کجای کد باید شماره و پیام مورد نظر را وادر کرد ???
    ممنون میشم اگه جواب بدید ...

  2. #2
    Member
    تاریخ عضویت
    May 2016
    نوشته ها
    94
    و ماژول من شیلد جی اس ام sim900a و به صورت شیلد است ...

  3. #3
    مدیر گروه
    تاریخ عضویت
    Nov 2013
    محل سکونت
    ایران
    نوشته ها
    4,064
    سلام
    اگر منظور شما این کد هست
    کد:
    /*
     SMS receiver
    
    
     This sketch, for the Arduino GSM shield, waits for a SMS message
     and displays it through the Serial port.
    
    
     Circuit:
     * GSM shield attached to and Arduino
     * SIM card that can receive SMS messages
    
    
     created 25 Feb 2012
     by Javier Zorzano / TD
    
    
     This example is in the public domain.
    
    
     http://www.arduino.cc/en/Tutorial/GSMExamplesReceiveSMS
    
    
    */
    
    
    // include the GSM library
    #include <GSM.h>
    
    
    // PIN Number for the SIM
    #define PINNUMBER ""
    
    
    // initialize the library instances
    GSM gsmAccess;
    GSM_SMS sms;
    
    
    // Array to hold the number a SMS is retreived from
    char senderNumber[20];
    
    
    void setup() {
      // initialize serial communications and wait for port to open:
      Serial.begin(9600);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }
    
    
      Serial.println("SMS Messages Receiver");
    
    
      // connection state
      boolean notConnected = true;
    
    
      // Start GSM connection
      while (notConnected) {
        if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
          notConnected = false;
        } else {
          Serial.println("Not connected");
          delay(1000);
        }
      }
    
    
      Serial.println("GSM initialized");
      Serial.println("Waiting for messages");
    }
    
    
    void loop() {
      char c;
    
    
      // If there are any SMSs available()
      if (sms.available()) {
        Serial.println("Message received from:");
    
    
        // Get remote number
        sms.remoteNumber(senderNumber, 20);
        Serial.println(senderNumber);
    
    
        // An example of message disposal
        // Any messages starting with # should be discarded
        if (sms.peek() == '#') {
          Serial.println("Discarded SMS");
          sms.flush();
        }
    
    
        // Read message bytes and print them
        while (c = sms.read()) {
          Serial.print(c);
        }
    
    
        Serial.println("\nEND OF MESSAGE");
    
    
        // Delete message from modem memory
        sms.flush();
        Serial.println("MESSAGE DELETED");
      }
    
    
      delay(1000);
    
    
    }
    اگه بخواید برای ماژول های GSM غیر اورجینال استفاده کنید باید یه سری تغییرات بدید که اگر در کدنویسی وارد نیستید بهتره برید سراغ کدهای ساده تر
    مثلا این کد:
    کد:
    
    
     
    
    
    // EN: String buffer for the GPRS shield message
    String msg = String("");
    // EN: Set to 1 when the next GPRS shield message will contains the SMS message
    int SmsContentFlag = 0;
    //control pins of relay.
    int relay_a=4;
    int relay_b=5;
    int relay_c=6;
    int relay_d=7;
    
    
    // EN: Code PIN of the SIM card (if applied)
    //String SIM_PIN_CODE = String( "XXXX" );
     
    void setup()
    {
      Serial.begin(19200);                 // the GPRS baud rate
      // Initialize  PINs
      pinMode( 4, OUTPUT ); 
      pinMode( 5, OUTPUT ); 
      pinMode( 6, OUTPUT ); 
      pinMode( 7, OUTPUT ); 
      digitalWrite( 4, LOW ); 
      digitalWrite( 5, LOW ); 
      digitalWrite( 6, LOW );
      digitalWrite( 7, LOW );
     Serial.println( "AT+CMGF=1" ); 
     delay(200);
    }
     
    void loop()
    {
        char SerialInByte;
        if(Serial.available())
        {       
            SerialInByte = (unsigned char)Serial.read();
           delay(5);
            
            // -------------------------------------------------------------------
            // EN: Program also listen to the GPRS shield message.
            // -------------------------------------------------------------------
           // EN: If the message ends with <CR> then process the message
            if( SerialInByte == 13 ){
              // EN: Store the char into the message buffer
              ProcessGprsMsg();
             }
             if( SerialInByte == 10 ){
                // EN: Skip Line feed
             }
             else {
               // EN: store the current character in the message string buffer
               msg += String(SerialInByte);
             }
         }   
    }
    // EN: Make action based on the content of the SMS. 
    //     Notice than SMS content is the result of the processing of several GPRS shield messages.
    void ProcessSms( String sms ){
      
      if( sms.indexOf("ona") >= 0 ){
        digitalWrite( relay_a, HIGH );
      }
       if( sms.indexOf("onb") >= 0 ){
        digitalWrite(  relay_b, HIGH );
      }
       if( sms.indexOf("onc") >= 0 ){
        digitalWrite(  relay_c, HIGH );
      }
      if( sms.indexOf("ond") >= 0 ){
        digitalWrite(  relay_d, HIGH );
      }
      if( sms.indexOf("offa") >= 0 ){
        digitalWrite(  relay_a, LOW );
      }
      if( sms.indexOf("offb") >= 0 ){
        digitalWrite(  relay_b, LOW );
      }
      if( sms.indexOf("offc") >= 0 ){
        digitalWrite(  relay_c, LOW );
      }
      if( sms.indexOf("offd") >= 0 ){
        digitalWrite(  relay_d, LOW );
      }
    }
    // EN: Request Text Mode for SMS messaging
    void GprsTextModeSMS(){
      Serial.println( "AT+CMGF=1" );
    }
    
    
    void GprsReadSmsStore( String SmsStorePos ){
      Serial.print( "AT+CMGR=" );
      Serial.println( SmsStorePos );
    }
    
    
    // EN: Clear the GPRS shield message buffer
    void ClearGprsMsg(){
      msg = "";
    }
    
    
    // EN: interpret the GPRS shield message and act appropiately
    void ProcessGprsMsg() {
      if( msg.indexOf( "Call Ready" ) >= 0 ){
       //  Serial.println( "*** GPRS Shield registered on Mobile Network ***" );
         GprsTextModeSMS();
      }
      
      // EN: unsolicited message received when getting a SMS message
      if( msg.indexOf( "+CMTI" ) >= 0 ){
       //  Serial.println( "*** SMS Received ***" );
         // EN: Look for the coma in the full message (+CMTI: "SM",6)
         //     In the sample, the SMS is stored at position 6
         int iPos = msg.indexOf( "," );
         String SmsStorePos = msg.substring( iPos+1 );
       //  Serial.print( "SMS stored at " );
      //   Serial.println( SmsStorePos );     
         // EN: Ask to read the SMS store
         GprsReadSmsStore( SmsStorePos );
      }
      
      // EN: SMS store readed through UART (result of GprsReadSmsStore request)  
      if( msg.indexOf( "+CMGR:" ) >= 0 ){
        // EN: Next message will contains the BODY of SMS
        SmsContentFlag = 1;
        // EN: Following lines are essentiel to not clear the flag!
        ClearGprsMsg();
        return;
      }
      
      // EN: +CMGR message just before indicate that the following GRPS Shield message 
      //     (this message) will contains the SMS body 
      if( SmsContentFlag == 1 ){
     //   Serial.println( "*** SMS MESSAGE CONTENT ***" );
     //   Serial.println( msg );
     //   Serial.println( "*** END OF SMS MESSAGE ***" );
        ProcessSms( msg );
      }
      
      ClearGprsMsg();
      // EN: Always clear the flag
      SmsContentFlag = 0; 
    }
    این کد یه نمونه هست که میاد بر اساس sms دریافتی چهار تا رله رو فعال / غیر فعال می کنه

  4. #4
    Member
    تاریخ عضویت
    May 2016
    نوشته ها
    94
    ایا از این ماژول هم میشه برای چیزی که گفتم استفاده کرد ؟؟
    ماژول GPRS / GSM چهار باند A6 دارای ارتباط سریال - پشتیبانی از AT Command


    اره میشه
    برای اس ام اس فرقی نمی کنه
    ویرایش توسط magmagmary : 08-22-2016 در ساعت 11:38 AM

  5. #5
    Member
    تاریخ عضویت
    May 2016
    نوشته ها
    94
    اما من هر چه گشتم کدی در این مورد پیدا نکردم برای این ماژول ....

  6. #6
    مدیر گروه
    تاریخ عضویت
    Nov 2013
    محل سکونت
    ایران
    نوشته ها
    4,064
    نقل قول نوشته اصلی توسط peyman180 نمایش پست ها
    اما من هر چه گشتم کدی در این مورد پیدا نکردم برای این ماژول ....
    چک کنید اگر کامندهای هر دو ماژول GSM مثل هم باشن میتونید از همون کد های sim900 هم استفاده کنید

مجوز های ارسال و ویرایش

  • شما نمیتوانید موضوع جدیدی ارسال کنید
  • شما امکان ارسال پاسخ را ندارید
  • شما نمیتوانید فایل پیوست کنید.
  • شما نمیتوانید پست های خود را ویرایش کنید
  •  

SEO by vBSEO