{"id":273190,"date":"2016-01-29T12:23:02","date_gmt":"2016-01-29T09:23:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=273190"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=273190","title":{"rendered":"Android \u0438 Arduino \u2014 \u0441\u043b\u0430\u0434\u043a\u0430\u044f \u043f\u0430\u0440\u043e\u0447\u043a\u0430"},"content":{"rendered":"<p>       <cut\/>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0425\u0430\u0431\u0440\u0430\u0445\u0430\u0431\u0440.<br \/>  \u0412 \u0441\u0435\u0442\u0438 \u043d\u0435 \u0440\u0430\u0437 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0430\u0441\u044c \u0442\u0435\u043c\u0430 \u0441\u043f\u0430\u0440\u0438\u0432\u0430\u043d\u0438\u044f Androida \u0438 Arduino \u0447\u0435\u0440\u0435\u0437 bluetooth, \u043b\u0438\u0447\u043d\u043e \u043c\u0435\u043d\u044f \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0438\u043b\u0430 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f -.<\/p>\n<p>  \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0432\u0441\u0451 \u043d\u0430\u0447\u0430\u043b\u043e\u0441\u044c.\u0414\u043e\u043c\u0430 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0451\u0440 Arduino Uno, \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0432\u0435\u0442\u043e\u043c.\u0412\u043e\u0437\u043b\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0434\u0432\u0435\u0440\u0438 \u0432 \u043a\u0432\u0430\u0440\u0442\u0438\u0440\u0443 <br \/>  \u0432 \u043f\u0430\u0440\u0430\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0442\u0435\u043c\u043d\u043e, \u0445\u043e\u0442\u044c \u0433\u043b\u0430\u0441 \u0432\u044b\u043a\u043e\u043b\u0438.\u0420\u0435\u0448\u0430\u044f \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u043d\u0430\u0434 \u0434\u0432\u0435\u0440\u044c\u044e \u0444\u043e\u043d\u0430\u0440\u044c, \u0430 \u0435\u0433\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0432\u0435\u0441\u0438\u043b \u043d\u0430 Arduino.\u0412\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e, \u0432\u044b\u0445\u043e\u0434\u044f \u0438\u0437 \u0434\u043e\u043c\u0430 \u0436\u043c\u0435\u0448\u044c \u043a\u043d\u043e\u043f\u043a\u0443 \u0438 \u043d\u0430 \u0442\u0440\u0438 \u043c\u0438\u043d\u0443\u0442\u044b \u0437\u0430\u0433\u043e\u0440\u0430\u0435\u0442\u0441\u044f \u0444\u043e\u043d\u0430\u0440\u044c.\u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0437\u0430\u043f\u0435\u0440\u0435\u0442\u044c \u0434\u0432\u0435\u0440\u044c \u0438 \u0443\u0439\u0442\u0438.\u0410 \u043f\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0438, \u0441 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u0447\u0435\u0440\u0435\u0437 bluetooth \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0448\u044c \u0444\u043e\u043d\u0430\u0440\u044c \u0441\u043d\u043e\u0432\u0430.\u0414\u043b\u044f \u043c\u0435\u043d\u044f \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e.<\/p>\n<p>  \u0418 \u0442\u0443\u0442 \u043f\u0440\u0438\u0448\u043b\u0430 \u043c\u044b\u0441\u043b\u044c, \u0430 \u043d\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c \u043b\u0438 \u044d\u0442\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u0443.\u0418 \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u043d\u0430 Arduino \u0434\u0430\u0442\u0447\u0438\u043a \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f, \u0441\u043e\u043e\u0440\u0443\u0434\u0438\u0432 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u0434\u043e\u0431\u0438\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.\u0414\u043b\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u043d\u0430\u0448\u0451\u043b\u0441\u044f \u0441\u0442\u0430\u0440\u0435\u043d\u044c\u043a\u0438\u0439 \u0441\u043c\u0430\u0440\u0442\u0444\u043e\u043d \u043d\u0430 Android 2.3, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0437\u0433 \u0434\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438.<\/p>\n<p>  \u0421\u0445\u0435\u043c\u0430 \u043f\u0440\u043e\u0441\u0442\u0430, \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0434\u0430\u0442\u0447\u0438\u043a \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f Arduino \u0447\u0435\u0440\u0435\u0437 bluetooth \u0448\u043b\u0451\u0442 \u0441\u0438\u0433\u043d\u0430\u043b \u043d\u0430 Android \u0442\u0435\u043b\u0435\u0444\u043e\u043d, \u0430 \u0442\u043e\u0442 \u0448\u043b\u0451\u0442 \u043c\u043d\u0435 \u0441\u043c\u0441 \u043e \u0441\u0440\u0430\u0431\u043e\u0442\u043a\u0435.<br \/>  \u041d\u043e \u0442\u0430\u043a\u0430\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430 \u0435\u0441\u043b\u0438 \u043d\u0430 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0435 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u043e \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.\u041f\u043e \u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u043e\u043d\u043d\u043e, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043c\u0441.\u0418 \u0435\u0449\u0451 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u043a\u0438, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043a\u0432\u0430\u0440\u0442\u0438\u0440\u0435.\u0422\u0430\u043a\u0436\u0435 \u0448\u043b\u0451\u0448\u044c \u0441\u043c\u0441 \u0441 \u043a\u043e\u0434\u043e\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c \u0438 Android \u0442\u0435\u0431\u0435 \u043f\u0435\u0440\u0435\u0437\u0432\u0430\u043d\u0438\u0432\u0430\u0435\u0442.\u0412\u044b\u0448\u0435\u043b \u0438\u0437 \u0434\u043e\u043c\u0430, \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b \u0441\u043c\u0441 \u0441 \u043a\u043e\u0434\u043e\u043c \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0430\u0441\u044c.\u041f\u043e\u0447\u0435\u043c\u0443 \u0432\u044b\u0431\u0440\u0430\u043b \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e \u0441\u043c\u0441, \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u043c\u043e\u0451\u043c \u0442\u0430\u0440\u0438\u0444\u0435 \u0441\u043e\u0442\u043e\u0432\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 500 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0445 \u0441\u043c\u0441, \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0451\u0440\u0442\u0432\u044b\u0439 \u0433\u0440\u0443\u0437.<\/p>\n<p>  \u0421\u043a\u0435\u0442\u0447 \u0434\u043b\u044f Arduino:<\/p>\n<pre><code class=\"cpp\">#define SENSOR_PIN  5\/\/ \u0434\u0430\u0442\u0447\u0438\u043a \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u0432\u0435\u0448\u0430\u0435\u043c \u043d\u0430 \u043f\u044f\u0442\u044b\u0439 \u043f\u0438\u043d  boolean inSensor ;  void setup() {     \/\/\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c UART     Serial.begin(9600);     \/\/  \u0432\u0445\u043e\u0434 \u0434\u0430\u0442\u0447\u0438\u043a\u0430    pinMode(SENSOR_PIN, INPUT);    } void loop() {    \/\/\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0434\u0430\u0442\u0447\u0438\u043a  if(inSensor==true){      \/\/\u0448\u043b\u0451\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0442\u0440\u0435\u0432\u043e\u0433\u0438     Serial.print(&quot;ALARM&quot;);              }  }  <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 SmsReceiver \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0435\u0433\u043e \u043e\u0442 BroadcastReceiver.<\/p>\n<pre><code class=\"java\">public class SmsReceiver extends BroadcastReceiver{  @Override \tpublic void onReceive(Context context, Intent intent)  \t{         \/\/  \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043c\u0441          Bundle bundle = intent.getExtras();                 SmsMessage[] msgs = null;         String str = &quot;&quot;;          String strBody = &quot;&quot;;          if (bundle != null)         {                         Object[] pdus = (Object[]) bundle.get(&quot;pdus&quot;);             msgs = new SmsMessage[pdus.length];                         for (int i=0; i&lt;msgs.length; i++){                 msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);                                 str = msgs[i].getOriginatingAddress();                                       strBody= msgs[i].getMessageBody().toString();                                    }                      \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u043c\u0441 \u043d\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0441 \u043d\u0430\u0448\u0438\u043c \u043a\u043e\u0434\u043e\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u0430\u043c          \/\/ \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435           if( strBody.equals(&quot;PUSK&quot;)){                          Intent intent1 = new Intent(context, MainActivity.class);             intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);              context.startActivity(intent1);             }             \/\/ \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0434\u043e\u0437\u0432\u043e\u043d           if( strBody.equals(&quot;CALL&quot;)){                                  Intent intent1 = new Intent(context, Call.class);                 intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);                                 context.startActivity(intent1);                 } } <\/code><\/pre>\n<p>  \u041f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0434\u043e\u0437\u0432\u043e\u043d\u0430.<\/p>\n<pre><code class=\"java\">public class Call extends Activity{ \t  \t@Override \tprotected void onCreate(Bundle savedInstanceState) { \t\tsuper.onCreate(savedInstanceState); \t\tsetContentView(R.layout.activity_main); \t\t\t \t\t \t\t        dialNumber();                 finish(); \t        }  \t\/\/ \u0437\u0432\u043e\u043d\u043e\u043a \u043d\u0430 \u0432\u0430\u0448 \u043d\u043e\u043c\u0435\u0440 \t\tpublic  void dialNumber() { \t\t\tIntent intent = new Intent(Intent.ACTION_CALL); \t\t\tintent.setData(Uri.parse(&quot;tel:&quot; + &quot;\u0412\u0410\u0428_\u041d\u041e\u041c\u0415\u0420&quot;)); \t\t\tstartActivity(intent); \t\t} } <\/code><\/pre>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441\u0435 MainActivity \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 Arduino \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c Handler.<\/p>\n<pre><code class=\"java\"> h = new Handler() {             public void handleMessage(android.os.Message msg) {               switch (msg.what) {               case ArduinoData: \t        \t  byte[] readBuf = (byte[]) msg.obj; \t              String strIncom = new String(readBuf, 0, msg.arg1);                                          \t                                    \/\/ \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0438\u0440\u0435\u043d\u0443                       \/\/ \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u043c\u0443\u0437\u044b\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0434\u043b\u044f  \u044d\u0444\u0444\u0435\u043a\u0442\u0430  \t              Context appContext = getApplicationContext(); \t              @SuppressWarnings(&quot;unused&quot;) \t                MediaPlayer resourcePlayer = MediaPlayer.create(appContext,R.raw.sirena); \t                resourcePlayer.start();                              \t             \/\/ \u0440\u0430\u0437\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u0432\u044f\u0437\u044c \u0441 Arduino \u0448\u043b\u0451\u043c \u0441\u043c\u0441 \u0438 \u0443\u0431\u0438\u0432\u0430\u0435\u043c Activity \t              try { \t      \t        btSocket.close(); \t      \t      setTitle(&quot;***\u0420\u0430\u0437\u0440\u044b\u0432***&quot;); \t      \t      } catch (IOException e2) { \t      \t         \t       \t      \t      } \t               \t              sendSms(&quot;\u0412\u0410\u0428_\u041d\u041e\u041c\u0415\u0420&quot;, &quot;***ALARM***ALARM***ALARM***&quot;); \t            \t              finish();          \t              break;               }             };           }; <\/code><\/pre>\n<p>  \u041c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043c\u0441.<\/p>\n<pre><code class=\"java\">\/\/ \u041e\u0442\u0441\u044b\u043b\u043a\u0430 \u0441\u043c\u0441 \t    public synchronized void sendSms(String numphone, String txt) { \t        try {             \t            if (smsWait) { \t                return; \t            } \t            smsWait=true; \t            PendingIntent sendResult = createPendingResult(ReqCodeSms,  \t            getIntent(), 0); \t            SmsManager.getDefault().sendTextMessage(numphone, null, txt,  \t            sendResult, null); \t            setTitle(&quot;***\u0421\u043c\u0441 \u0443\u0448\u043b\u043e***&quot;); \t             \t             \t        } catch (Exception e) { \t            e.printStackTrace(); \t            setTitle(&quot;***\u0421\u043c\u0441 \u043d\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e***&quot;); \t        }        } <\/code><\/pre>\n<p>  \u041f\u043e\u043a\u0430 \u0432\u0441\u0451.\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0437\u0430\u0431\u0430\u0432\u043d\u0430\u044f \u0438\u0433\u0440\u0443\u0448\u043a\u0430 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u0432\u0435\u0449\u044c.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/276161\/\"> https:\/\/habrahabr.ru\/post\/276161\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       <cut\/>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0425\u0430\u0431\u0440\u0430\u0445\u0430\u0431\u0440.<br \/>  \u0412 \u0441\u0435\u0442\u0438 \u043d\u0435 \u0440\u0430\u0437 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0430\u0441\u044c \u0442\u0435\u043c\u0430 \u0441\u043f\u0430\u0440\u0438\u0432\u0430\u043d\u0438\u044f Androida \u0438 Arduino \u0447\u0435\u0440\u0435\u0437 bluetooth, \u043b\u0438\u0447\u043d\u043e \u043c\u0435\u043d\u044f \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0438\u043b\u0430 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f -.<\/p>\n<p>  \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0432\u0441\u0451 \u043d\u0430\u0447\u0430\u043b\u043e\u0441\u044c.\u0414\u043e\u043c\u0430 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0451\u0440 Arduino Uno, \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0432\u0435\u0442\u043e\u043c.\u0412\u043e\u0437\u043b\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0434\u0432\u0435\u0440\u0438 \u0432 \u043a\u0432\u0430\u0440\u0442\u0438\u0440\u0443 <br \/>  \u0432 \u043f\u0430\u0440\u0430\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0442\u0435\u043c\u043d\u043e, \u0445\u043e\u0442\u044c \u0433\u043b\u0430\u0441 \u0432\u044b\u043a\u043e\u043b\u0438.\u0420\u0435\u0448\u0430\u044f \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u043d\u0430\u0434 \u0434\u0432\u0435\u0440\u044c\u044e \u0444\u043e\u043d\u0430\u0440\u044c, \u0430 \u0435\u0433\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0432\u0435\u0441\u0438\u043b \u043d\u0430 Arduino.\u0412\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e, \u0432\u044b\u0445\u043e\u0434\u044f \u0438\u0437 \u0434\u043e\u043c\u0430 \u0436\u043c\u0435\u0448\u044c \u043a\u043d\u043e\u043f\u043a\u0443 \u0438 \u043d\u0430 \u0442\u0440\u0438 \u043c\u0438\u043d\u0443\u0442\u044b \u0437\u0430\u0433\u043e\u0440\u0430\u0435\u0442\u0441\u044f \u0444\u043e\u043d\u0430\u0440\u044c.\u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0437\u0430\u043f\u0435\u0440\u0435\u0442\u044c \u0434\u0432\u0435\u0440\u044c \u0438 \u0443\u0439\u0442\u0438.\u0410 \u043f\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0438, \u0441 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u0447\u0435\u0440\u0435\u0437 bluetooth \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0448\u044c \u0444\u043e\u043d\u0430\u0440\u044c \u0441\u043d\u043e\u0432\u0430.\u0414\u043b\u044f \u043c\u0435\u043d\u044f \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e.<\/p>\n<p>  \u0418 \u0442\u0443\u0442 \u043f\u0440\u0438\u0448\u043b\u0430 \u043c\u044b\u0441\u043b\u044c, \u0430 \u043d\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c \u043b\u0438 \u044d\u0442\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u0443.\u0418 \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u043d\u0430 Arduino \u0434\u0430\u0442\u0447\u0438\u043a \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f, \u0441\u043e\u043e\u0440\u0443\u0434\u0438\u0432 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u0434\u043e\u0431\u0438\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.\u0414\u043b\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u043d\u0430\u0448\u0451\u043b\u0441\u044f \u0441\u0442\u0430\u0440\u0435\u043d\u044c\u043a\u0438\u0439 \u0441\u043c\u0430\u0440\u0442\u0444\u043e\u043d \u043d\u0430 Android 2.3, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0437\u0433 \u0434\u0430\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438.<\/p>\n<p>  \u0421\u0445\u0435\u043c\u0430 \u043f\u0440\u043e\u0441\u0442\u0430, \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0434\u0430\u0442\u0447\u0438\u043a \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f Arduino \u0447\u0435\u0440\u0435\u0437 bluetooth \u0448\u043b\u0451\u0442 \u0441\u0438\u0433\u043d\u0430\u043b \u043d\u0430 Android \u0442\u0435\u043b\u0435\u0444\u043e\u043d, \u0430 \u0442\u043e\u0442 \u0448\u043b\u0451\u0442 \u043c\u043d\u0435 \u0441\u043c\u0441 \u043e \u0441\u0440\u0430\u0431\u043e\u0442\u043a\u0435.<br \/>  \u041d\u043e \u0442\u0430\u043a\u0430\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430 \u0435\u0441\u043b\u0438 \u043d\u0430 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0435 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u043e \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.\u041f\u043e \u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u043e\u043d\u043d\u043e, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043c\u0441.\u0418 \u0435\u0449\u0451 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u043a\u0438, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043a\u0432\u0430\u0440\u0442\u0438\u0440\u0435.\u0422\u0430\u043a\u0436\u0435 \u0448\u043b\u0451\u0448\u044c \u0441\u043c\u0441 \u0441 \u043a\u043e\u0434\u043e\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c \u0438 Android \u0442\u0435\u0431\u0435 \u043f\u0435\u0440\u0435\u0437\u0432\u0430\u043d\u0438\u0432\u0430\u0435\u0442.\u0412\u044b\u0448\u0435\u043b \u0438\u0437 \u0434\u043e\u043c\u0430, \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b \u0441\u043c\u0441 \u0441 \u043a\u043e\u0434\u043e\u043c \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0430\u0441\u044c.\u041f\u043e\u0447\u0435\u043c\u0443 \u0432\u044b\u0431\u0440\u0430\u043b \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e \u0441\u043c\u0441, \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u043c\u043e\u0451\u043c \u0442\u0430\u0440\u0438\u0444\u0435 \u0441\u043e\u0442\u043e\u0432\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 500 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0445 \u0441\u043c\u0441, \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0451\u0440\u0442\u0432\u044b\u0439 \u0433\u0440\u0443\u0437.<\/p>\n<p>  \u0421\u043a\u0435\u0442\u0447 \u0434\u043b\u044f Arduino:<\/p>\n<pre><code class=\"cpp\">#define SENSOR_PIN  5\/\/ \u0434\u0430\u0442\u0447\u0438\u043a \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u0432\u0435\u0448\u0430\u0435\u043c \u043d\u0430 \u043f\u044f\u0442\u044b\u0439 \u043f\u0438\u043d  boolean inSensor ;  void setup() {     \/\/\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c UART     Serial.begin(9600);     \/\/  \u0432\u0445\u043e\u0434 \u0434\u0430\u0442\u0447\u0438\u043a\u0430    pinMode(SENSOR_PIN, INPUT);    } void loop() {    \/\/\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0434\u0430\u0442\u0447\u0438\u043a  if(inSensor==true){      \/\/\u0448\u043b\u0451\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0442\u0440\u0435\u0432\u043e\u0433\u0438     Serial.print(&quot;ALARM&quot;);              }  }  <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 SmsReceiver \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u0435\u0433\u043e \u043e\u0442 BroadcastReceiver.<\/p>\n<pre><code class=\"java\">public class SmsReceiver extends BroadcastReceiver{  @Override \tpublic void onReceive(Context context, Intent intent)  \t{         \/\/  \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043c\u0441          Bundle bundle = intent.getExtras();                 SmsMessage[] msgs = null;         String str = &quot;&quot;;          String strBody = &quot;&quot;;          if (bundle != null)         {                         Object[] pdus = (Object[]) bundle.get(&quot;pdus&quot;);             msgs = new SmsMessage[pdus.length];                         for (int i=0; i&lt;msgs.length; i++){                 msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);                                 str = msgs[i].getOriginatingAddress();                                       strBody= msgs[i].getMessageBody().toString();                                    }                      \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u043c\u0441 \u043d\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0441 \u043d\u0430\u0448\u0438\u043c \u043a\u043e\u0434\u043e\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u0430\u043c          \/\/ \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435           if( strBody.equals(&quot;PUSK&quot;)){                          Intent intent1 = new Intent(context, MainActivity.class);             intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);              context.startActivity(intent1);             }             \/\/ \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0434\u043e\u0437\u0432\u043e\u043d           if( strBody.equals(&quot;CALL&quot;)){                                  Intent intent1 = new Intent(context, Call.class);                 intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);                                 context.startActivity(intent1);                 } } <\/code><\/pre>\n<p>  \u041f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0434\u043e\u0437\u0432\u043e\u043d\u0430.<\/p>\n<pre><code class=\"java\">public class Call extends Activity{ \t  \t@Override \tprotected void onCreate(Bundle savedInstanceState) { \t\tsuper.onCreate(savedInstanceState); \t\tsetContentView(R.layout.activity_main); \t\t\t \t\t \t\t        dialNumber();                 finish(); \t        }  \t\/\/ \u0437\u0432\u043e\u043d\u043e\u043a \u043d\u0430 \u0432\u0430\u0448 \u043d\u043e\u043c\u0435\u0440 \t\tpublic  void dialNumber() { \t\t\tIntent intent = new Intent(Intent.ACTION_CALL); \t\t\tintent.setData(Uri.parse(&quot;tel:&quot; + &quot;\u0412\u0410\u0428_\u041d\u041e\u041c\u0415\u0420&quot;)); \t\t\tstartActivity(intent); \t\t} } <\/code><\/pre>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441\u0435 MainActivity \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 Arduino \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c Handler.<\/p>\n<pre><code class=\"java\"> h = new Handler() {             public void handleMessage(android.os.Message msg) {               switch (msg.what) {               case ArduinoData: \t        \t  byte[] readBuf = (byte[]) msg.obj; \t              String strIncom = new String(readBuf, 0, msg.arg1);                                          \t                                    \/\/ \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0438\u0440\u0435\u043d\u0443                       \/\/ \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u043c\u0443\u0437\u044b\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0434\u043b\u044f  \u044d\u0444\u0444\u0435\u043a\u0442\u0430  \t              Context appContext = getApplicationContext(); \t              @SuppressWarnings(&quot;unused&quot;) \t                MediaPlayer resourcePlayer = MediaPlayer.create(appContext,R.raw.sirena); \t                resourcePlayer.start();                              \t             \/\/ \u0440\u0430\u0437\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u0432\u044f\u0437\u044c \u0441 Arduino \u0448\u043b\u0451\u043c \u0441\u043c\u0441 \u0438 \u0443\u0431\u0438\u0432\u0430\u0435\u043c Activity \t              try { \t      \t        btSocket.close(); \t      \t      setTitle(&quot;***\u0420\u0430\u0437\u0440\u044b\u0432***&quot;); \t      \t      } catch (IOException e2) { \t      \t         \t       \t      \t      } \t               \t              sendSms(&quot;\u0412\u0410\u0428_\u041d\u041e\u041c\u0415\u0420&quot;, &quot;***ALARM***ALARM***ALARM***&quot;); \t            \t              finish();          \t              break;               }             };           }; <\/code><\/pre>\n<p>  \u041c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043c\u0441.<\/p>\n<pre><code class=\"java\">\/\/ \u041e\u0442\u0441\u044b\u043b\u043a\u0430 \u0441\u043c\u0441 \t    public synchronized void sendSms(String numphone, String txt) { \t        try {             \t            if (smsWait) { \t                return; \t            } \t            smsWait=true; \t            PendingIntent sendResult = createPendingResult(ReqCodeSms,  \t            getIntent(), 0); \t            SmsManager.getDefault().sendTextMessage(numphone, null, txt,  \t            sendResult, null); \t            setTitle(&quot;***\u0421\u043c\u0441 \u0443\u0448\u043b\u043e***&quot;); \t             \t             \t        } catch (Exception e) { \t            e.printStackTrace(); \t            setTitle(&quot;***\u0421\u043c\u0441 \u043d\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e***&quot;); \t        }        } <\/code><\/pre>\n<p>  \u041f\u043e\u043a\u0430 \u0432\u0441\u0451.\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0437\u0430\u0431\u0430\u0432\u043d\u0430\u044f \u0438\u0433\u0440\u0443\u0448\u043a\u0430 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u0432\u0435\u0449\u044c.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/276161\/\"> https:\/\/habrahabr.ru\/post\/276161\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-273190","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/273190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=273190"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/273190\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=273190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=273190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=273190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}