├── .idea ├── .name ├── copyright │ └── profiles_settings.xml ├── dictionaries │ └── gerry.xml ├── scopes │ └── scope_settings.xml ├── encodings.xml ├── vcs.xml ├── inspectionProfiles │ ├── profiles_settings.xml │ └── Project_Default.xml ├── modules.xml ├── compiler.xml ├── misc.xml └── codeStyleSettings.xml ├── .gitignore ├── res ├── drawable │ ├── img.png │ ├── smart.png │ ├── ic_action_settings.png │ ├── buttonshape.xml │ ├── buttonshape_red.xml │ ├── ab_background_textured_esp8266iot.xml │ ├── main_header_selector.xml │ ├── selectable_background_esp8266iot.xml │ ├── btn_cab_done_esp8266iot.xml │ ├── spinner_background_ab_esp8266iot.xml │ ├── progress_horizontal_esp8266iot.xml │ └── tab_indicator_ab_esp8266iot.xml ├── drawable-hdpi │ ├── app_icon.png │ ├── ic_launcher.png │ ├── ic_action_settings.png │ ├── ab_solid_esp8266iot.9.png │ ├── progress_bg_esp8266iot.9.png │ ├── ab_texture_tile_esp8266iot.png │ ├── ab_transparent_esp8266iot.9.png │ ├── list_focused_esp8266iot.9.png │ ├── list_pressed_esp8266iot.9.png │ ├── tab_selected_esp8266iot.9.png │ ├── tab_unselected_esp8266iot.9.png │ ├── ab_bottom_solid_esp8266iot.9.png │ ├── ab_stacked_solid_esp8266iot.9.png │ ├── progress_primary_esp8266iot.9.png │ ├── cab_background_top_esp8266iot.9.png │ ├── menu_dropdown_panel_esp8266iot.9.png │ ├── progress_secondary_esp8266iot.9.png │ ├── spinner_ab_default_esp8266iot.9.png │ ├── spinner_ab_disabled_esp8266iot.9.png │ ├── spinner_ab_focused_esp8266iot.9.png │ ├── spinner_ab_pressed_esp8266iot.9.png │ ├── btn_cab_done_default_esp8266iot.9.png │ ├── btn_cab_done_focused_esp8266iot.9.png │ ├── btn_cab_done_pressed_esp8266iot.9.png │ ├── cab_background_bottom_esp8266iot.9.png │ ├── tab_selected_focused_esp8266iot.9.png │ ├── tab_selected_pressed_esp8266iot.9.png │ ├── tab_unselected_focused_esp8266iot.9.png │ └── tab_unselected_pressed_esp8266iot.9.png ├── drawable-mdpi │ ├── app_icon.png │ ├── ic_action_settings.png │ ├── ab_solid_esp8266iot.9.png │ ├── progress_bg_esp8266iot.9.png │ ├── ab_texture_tile_esp8266iot.png │ ├── ab_transparent_esp8266iot.9.png │ ├── list_focused_esp8266iot.9.png │ ├── list_pressed_esp8266iot.9.png │ ├── tab_selected_esp8266iot.9.png │ ├── tab_unselected_esp8266iot.9.png │ ├── ab_bottom_solid_esp8266iot.9.png │ ├── ab_stacked_solid_esp8266iot.9.png │ ├── progress_primary_esp8266iot.9.png │ ├── cab_background_top_esp8266iot.9.png │ ├── menu_dropdown_panel_esp8266iot.9.png │ ├── progress_secondary_esp8266iot.9.png │ ├── spinner_ab_default_esp8266iot.9.png │ ├── spinner_ab_disabled_esp8266iot.9.png │ ├── spinner_ab_focused_esp8266iot.9.png │ ├── spinner_ab_pressed_esp8266iot.9.png │ ├── btn_cab_done_default_esp8266iot.9.png │ ├── btn_cab_done_focused_esp8266iot.9.png │ ├── btn_cab_done_pressed_esp8266iot.9.png │ ├── cab_background_bottom_esp8266iot.9.png │ ├── tab_selected_focused_esp8266iot.9.png │ ├── tab_selected_pressed_esp8266iot.9.png │ ├── tab_unselected_focused_esp8266iot.9.png │ └── tab_unselected_pressed_esp8266iot.9.png ├── drawable-xhdpi │ ├── app_icon.png │ ├── ic_action_settings.png │ ├── ab_solid_esp8266iot.9.png │ ├── ab_texture_tile_esp8266iot.png │ ├── list_focused_esp8266iot.9.png │ ├── list_pressed_esp8266iot.9.png │ ├── progress_bg_esp8266iot.9.png │ ├── tab_selected_esp8266iot.9.png │ ├── ab_bottom_solid_esp8266iot.9.png │ ├── ab_transparent_esp8266iot.9.png │ ├── tab_unselected_esp8266iot.9.png │ ├── ab_stacked_solid_esp8266iot.9.png │ ├── cab_background_top_esp8266iot.9.png │ ├── progress_primary_esp8266iot.9.png │ ├── progress_secondary_esp8266iot.9.png │ ├── spinner_ab_default_esp8266iot.9.png │ ├── spinner_ab_focused_esp8266iot.9.png │ ├── spinner_ab_pressed_esp8266iot.9.png │ ├── btn_cab_done_default_esp8266iot.9.png │ ├── btn_cab_done_focused_esp8266iot.9.png │ ├── btn_cab_done_pressed_esp8266iot.9.png │ ├── menu_dropdown_panel_esp8266iot.9.png │ ├── spinner_ab_disabled_esp8266iot.9.png │ ├── tab_selected_focused_esp8266iot.9.png │ ├── tab_selected_pressed_esp8266iot.9.png │ ├── cab_background_bottom_esp8266iot.9.png │ ├── tab_unselected_focused_esp8266iot.9.png │ └── tab_unselected_pressed_esp8266iot.9.png ├── drawable-xxhdpi │ ├── app_icon.png │ ├── ic_action_settings.png │ ├── ab_solid_esp8266iot.9.png │ ├── list_focused_esp8266iot.9.png │ ├── list_pressed_esp8266iot.9.png │ ├── progress_bg_esp8266iot.9.png │ ├── tab_selected_esp8266iot.9.png │ ├── ab_texture_tile_esp8266iot.png │ ├── ab_transparent_esp8266iot.9.png │ ├── tab_unselected_esp8266iot.9.png │ ├── ab_bottom_solid_esp8266iot.9.png │ ├── ab_stacked_solid_esp8266iot.9.png │ ├── progress_primary_esp8266iot.9.png │ ├── cab_background_top_esp8266iot.9.png │ ├── menu_dropdown_panel_esp8266iot.9.png │ ├── progress_secondary_esp8266iot.9.png │ ├── spinner_ab_default_esp8266iot.9.png │ ├── spinner_ab_disabled_esp8266iot.9.png │ ├── spinner_ab_focused_esp8266iot.9.png │ ├── spinner_ab_pressed_esp8266iot.9.png │ ├── btn_cab_done_default_esp8266iot.9.png │ ├── btn_cab_done_focused_esp8266iot.9.png │ ├── btn_cab_done_pressed_esp8266iot.9.png │ ├── cab_background_bottom_esp8266iot.9.png │ ├── tab_selected_focused_esp8266iot.9.png │ ├── tab_selected_pressed_esp8266iot.9.png │ ├── tab_unselected_focused_esp8266iot.9.png │ └── tab_unselected_pressed_esp8266iot.9.png ├── values │ ├── dimens.xml │ ├── arrays.xml │ ├── strings.xml │ └── styles_esp8266iot.xml ├── layout │ ├── delete_station.xml │ ├── main_activity.xml │ ├── db_edit_name_dialog.xml │ ├── main_smartlink.xml │ └── setup_activity.xml └── menu │ └── menu.xml ├── README.md ├── src ├── com │ └── espressif │ │ └── esp8266_iot │ │ ├── activitys │ │ ├── smartlinkActivity.java │ │ ├── EspWifiAdminSimple.java │ │ └── setupActivity.java │ │ ├── task │ │ ├── IEsptouchGenerator.java │ │ ├── ICodeData.java │ │ ├── __IEsptouchTask.java │ │ ├── IEsptouchTaskParameter.java │ │ ├── EsptouchTaskParameter.java │ │ └── __EsptouchTask.java │ │ ├── udp │ │ ├── MyBroadcastReceiver.java │ │ ├── UDPListenerService.java │ │ ├── UDPSocketClient.java │ │ └── UDPSocketServer.java │ │ ├── IEsptouchResult.java │ │ ├── DataStore │ │ ├── DataStore_Name.java │ │ ├── DataStore_Data.java │ │ ├── DatabaseHandler_Name.java │ │ └── DatabaseHandler_Data.java │ │ ├── protocol │ │ ├── GuideCode.java │ │ ├── EsptouchGenerator.java │ │ ├── DataCode.java │ │ └── DatumCode.java │ │ ├── EsptouchResult.java │ │ ├── util │ │ ├── CRC16CCITT.java │ │ ├── CRC8.java │ │ ├── BaseActivity.java │ │ ├── EspNetUtil.java │ │ └── ByteUtil.java │ │ ├── IEsptouchTask.java │ │ ├── EsptouchTask.java │ │ └── GlobalClass.java └── net │ └── shikii │ └── widgets │ └── SAutoBgButton.java ├── ESP8266_IOT.iml ├── .project ├── ESPRESSIF MIT LICENSE V1.LICENSE └── AndroidManifest.xml /.idea/.name: -------------------------------------------------------------------------------- 1 | ESP8266-IOT -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | gen/ 3 | out/ 4 | proguard/ 5 | out/ 6 | .DS_Store 7 | project.properties 8 | -------------------------------------------------------------------------------- /res/drawable/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable/img.png -------------------------------------------------------------------------------- /res/drawable/smart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable/smart.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESP8266-IOT-Android 2 |

Android App for ESP8266 Wlan/Wifi Relay

3 |

Control and Info App

4 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/dictionaries/gerry.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /res/drawable-hdpi/app_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/app_icon.png -------------------------------------------------------------------------------- /res/drawable-mdpi/app_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/app_icon.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/app_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/app_icon.png -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/app_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/app_icon.png -------------------------------------------------------------------------------- /res/drawable/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable/ic_action_settings.png -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/ic_action_settings.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/ic_action_settings.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/ic_action_settings.png -------------------------------------------------------------------------------- /res/drawable-hdpi/ab_solid_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/ab_solid_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ab_solid_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/ab_solid_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ab_solid_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/ab_solid_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/ic_action_settings.png -------------------------------------------------------------------------------- /res/drawable-hdpi/progress_bg_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/progress_bg_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/progress_bg_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/progress_bg_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ab_solid_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/ab_solid_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/ab_texture_tile_esp8266iot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/ab_texture_tile_esp8266iot.png -------------------------------------------------------------------------------- /res/drawable-hdpi/ab_transparent_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/ab_transparent_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/list_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/list_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/list_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/list_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/tab_selected_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/tab_selected_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/tab_unselected_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/tab_unselected_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ab_texture_tile_esp8266iot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/ab_texture_tile_esp8266iot.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ab_transparent_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/ab_transparent_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/list_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/list_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/list_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/list_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/tab_selected_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/tab_selected_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/tab_unselected_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/tab_unselected_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ab_texture_tile_esp8266iot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/ab_texture_tile_esp8266iot.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/list_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/list_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/list_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/list_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/progress_bg_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/progress_bg_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/tab_selected_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/tab_selected_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/list_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/list_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/list_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/list_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/progress_bg_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/progress_bg_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/tab_selected_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/tab_selected_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/ab_bottom_solid_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/ab_bottom_solid_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/ab_stacked_solid_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/ab_stacked_solid_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/progress_primary_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/progress_primary_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ab_bottom_solid_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/ab_bottom_solid_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ab_stacked_solid_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/ab_stacked_solid_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/progress_primary_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/progress_primary_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ab_bottom_solid_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/ab_bottom_solid_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ab_transparent_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/ab_transparent_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/tab_unselected_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/tab_unselected_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ab_texture_tile_esp8266iot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/ab_texture_tile_esp8266iot.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ab_transparent_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/ab_transparent_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/tab_unselected_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/tab_unselected_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/cab_background_top_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/cab_background_top_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/menu_dropdown_panel_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/menu_dropdown_panel_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/progress_secondary_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/progress_secondary_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/spinner_ab_default_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/spinner_ab_default_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/spinner_ab_disabled_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/spinner_ab_disabled_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/spinner_ab_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/spinner_ab_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/spinner_ab_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/spinner_ab_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/cab_background_top_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/cab_background_top_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/menu_dropdown_panel_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/menu_dropdown_panel_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/progress_secondary_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/progress_secondary_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/spinner_ab_default_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/spinner_ab_default_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/spinner_ab_disabled_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/spinner_ab_disabled_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/spinner_ab_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/spinner_ab_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/spinner_ab_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/spinner_ab_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ab_stacked_solid_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/ab_stacked_solid_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/cab_background_top_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/cab_background_top_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/progress_primary_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/progress_primary_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/progress_secondary_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/progress_secondary_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/spinner_ab_default_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/spinner_ab_default_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/spinner_ab_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/spinner_ab_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/spinner_ab_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/spinner_ab_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ab_bottom_solid_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/ab_bottom_solid_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ab_stacked_solid_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/ab_stacked_solid_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/progress_primary_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/progress_primary_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/btn_cab_done_default_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/btn_cab_done_default_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/btn_cab_done_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/btn_cab_done_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/btn_cab_done_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/btn_cab_done_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/cab_background_bottom_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/cab_background_bottom_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/tab_selected_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/tab_selected_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/tab_selected_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/tab_selected_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/btn_cab_done_default_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/btn_cab_done_default_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/btn_cab_done_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/btn_cab_done_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/btn_cab_done_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/btn_cab_done_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/cab_background_bottom_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/cab_background_bottom_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/tab_selected_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/tab_selected_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/tab_selected_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/tab_selected_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/btn_cab_done_default_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/btn_cab_done_default_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/btn_cab_done_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/btn_cab_done_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/btn_cab_done_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/btn_cab_done_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/menu_dropdown_panel_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/menu_dropdown_panel_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/spinner_ab_disabled_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/spinner_ab_disabled_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/tab_selected_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/tab_selected_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/tab_selected_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/tab_selected_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/cab_background_top_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/cab_background_top_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/menu_dropdown_panel_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/menu_dropdown_panel_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/progress_secondary_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/progress_secondary_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/spinner_ab_default_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/spinner_ab_default_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/spinner_ab_disabled_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/spinner_ab_disabled_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/spinner_ab_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/spinner_ab_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/spinner_ab_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/spinner_ab_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/tab_unselected_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/tab_unselected_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/tab_unselected_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-hdpi/tab_unselected_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/tab_unselected_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/tab_unselected_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-mdpi/tab_unselected_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-mdpi/tab_unselected_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/cab_background_bottom_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/cab_background_bottom_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/tab_unselected_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/tab_unselected_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/tab_unselected_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xhdpi/tab_unselected_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/btn_cab_done_default_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/btn_cab_done_default_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/btn_cab_done_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/btn_cab_done_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/btn_cab_done_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/btn_cab_done_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/cab_background_bottom_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/cab_background_bottom_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/tab_selected_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/tab_selected_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/tab_selected_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/tab_selected_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/tab_unselected_focused_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/tab_unselected_focused_esp8266iot.9.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/tab_unselected_pressed_esp8266iot.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/res/drawable-xxhdpi/tab_unselected_pressed_esp8266iot.9.png -------------------------------------------------------------------------------- /.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/activitys/smartlinkActivity.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gerrylenz/ESP8266-IOT-Android/HEAD/src/com/espressif/esp8266_iot/activitys/smartlinkActivity.java -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1 5 | 2 6 | 3 7 | 4 8 | 5 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/task/IEsptouchGenerator.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.task; 2 | 3 | public interface IEsptouchGenerator { 4 | /** 5 | * Get guide code by the format of byte[][] 6 | * 7 | * @return guide code by the format of byte[][] 8 | */ 9 | byte[][] getGCBytes2(); 10 | 11 | /** 12 | * Get data code by the format of byte[][] 13 | * 14 | * @return data code by the format of byte[][] 15 | */ 16 | byte[][] getDCBytes2(); 17 | } 18 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/task/ICodeData.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.task; 2 | 3 | /** 4 | * the class used to represent some code to be transformed by UDP socket should implement the interface 5 | * @author afunx 6 | * 7 | */ 8 | public interface ICodeData { 9 | /** 10 | * Get the byte[] to be transformed. 11 | * 12 | * 13 | * @return the byte[] to be transfromed 14 | */ 15 | byte[] getBytes(); 16 | 17 | /** 18 | * Get the char[](u8[]) to be transfromed. 19 | * 20 | * @return the char[](u8) to be transformed 21 | */ 22 | char[] getU8s(); 23 | } 24 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/udp/MyBroadcastReceiver.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.udp; 2 | 3 | /** 4 | * Created by gerry on 25.07.2015. 5 | */ 6 | 7 | import android.content.BroadcastReceiver; 8 | import android.content.Context; 9 | import android.content.Intent; 10 | import android.util.Log; 11 | import android.widget.Toast; 12 | 13 | public class MyBroadcastReceiver extends BroadcastReceiver { 14 | 15 | @Override 16 | public void onReceive(Context context, Intent intent) { 17 | 18 | Toast.makeText(context, "Time Changed", Toast.LENGTH_LONG).show(); 19 | Log.d("BROAD","Time"); 20 | } 21 | } -------------------------------------------------------------------------------- /res/layout/delete_station.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | -------------------------------------------------------------------------------- /ESP8266_IOT.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/IEsptouchResult.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot; 2 | 3 | import java.net.InetAddress; 4 | 5 | public interface IEsptouchResult { 6 | 7 | /** 8 | * check whether the esp8266_iot task is executed suc 9 | * 10 | * @return whether the esp8266_iot task is executed suc 11 | */ 12 | boolean isSuc(); 13 | 14 | /** 15 | * get the device's bssid 16 | * 17 | * @return the device's bssid 18 | */ 19 | String getBssid(); 20 | 21 | /** 22 | * check whether the esp8266_iot task is cancelled by user 23 | * 24 | * @return whether the esp8266_iot task is cancelled by user 25 | */ 26 | boolean isCancelled(); 27 | 28 | /** 29 | * get the ip address of the device 30 | * 31 | * @return the ip device of the device 32 | */ 33 | InetAddress getInetAddress(); 34 | } 35 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 23 | -------------------------------------------------------------------------------- /res/drawable/buttonshape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 14 | 20 | 24 | 28 | -------------------------------------------------------------------------------- /res/drawable/buttonshape_red.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 14 | 20 | 24 | 28 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ESP8266-IOT 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /res/drawable/ab_background_textured_esp8266iot.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/DataStore/DataStore_Name.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.DataStore; 2 | 3 | /** 4 | * Created by gerry on 22.07.2015. 5 | */ 6 | public class DataStore_Name { 7 | 8 | //private variables 9 | int _id; 10 | String _name; 11 | 12 | // Empty constructor 13 | public DataStore_Name() { 14 | 15 | } 16 | 17 | public DataStore_Name(int id) { 18 | this._id = id; 19 | } 20 | 21 | public DataStore_Name(int id, String name) { 22 | this._id = id; 23 | this._name = name; 24 | } 25 | 26 | // getting ID 27 | public int getID() { 28 | return this._id; 29 | } 30 | 31 | // setting id 32 | public void setID(int Value) { 33 | this._id = Value; 34 | } 35 | 36 | // getting name 37 | public String getName() { 38 | return this._name; 39 | } 40 | 41 | // setting name 42 | public void setName(String Value) { 43 | this._name = Value; 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /res/menu/menu.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 13 | 14 | 19 | 20 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /res/drawable/main_header_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | ------------------------------------------------- 13 | 14 | 21 | 22 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/protocol/GuideCode.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.protocol; 2 | 3 | import com.espressif.esp8266_iot.task.ICodeData; 4 | import com.espressif.esp8266_iot.util.ByteUtil; 5 | 6 | public class GuideCode implements ICodeData { 7 | 8 | public static final int GUIDE_CODE_LEN = 4; 9 | 10 | @Override 11 | public byte[] getBytes() { 12 | throw new RuntimeException("DataCode don't support getBytes()"); 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | StringBuilder sb = new StringBuilder(); 18 | char[] dataU8s = getU8s(); 19 | for (int i = 0; i < GUIDE_CODE_LEN; i++) { 20 | String hexString = ByteUtil.convertU8ToHexString(dataU8s[i]); 21 | sb.append("0x"); 22 | if (hexString.length() == 1) { 23 | sb.append("0"); 24 | } 25 | sb.append(hexString).append(" "); 26 | } 27 | return sb.toString(); 28 | } 29 | 30 | @Override 31 | public char[] getU8s() { 32 | char[] guidesU8s = new char[GUIDE_CODE_LEN]; 33 | guidesU8s[0] = 515; 34 | guidesU8s[1] = 514; 35 | guidesU8s[2] = 513; 36 | guidesU8s[3] = 512; 37 | return guidesU8s; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /res/layout/main_activity.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 14 | 15 | 21 | 22 | 23 | 24 | 25 | 33 | 34 | -------------------------------------------------------------------------------- /res/drawable/selectable_background_esp8266iot.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /res/drawable/btn_cab_done_esp8266iot.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 23 | 25 | 27 | 28 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/EsptouchResult.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot; 2 | 3 | import java.net.InetAddress; 4 | import java.util.concurrent.atomic.AtomicBoolean; 5 | 6 | public class EsptouchResult implements IEsptouchResult { 7 | 8 | private final boolean mIsSuc; 9 | private final String mBssid; 10 | private final InetAddress mInetAddress; 11 | private AtomicBoolean mIsCancelled; 12 | 13 | /** 14 | * Constructor of EsptouchResult 15 | * 16 | * @param isSuc whether the esp8266_iot task is executed suc 17 | * @param bssid the device's bssid 18 | * @param inetAddress the device's ip address 19 | */ 20 | public EsptouchResult(boolean isSuc, String bssid,InetAddress inetAddress) { 21 | this.mIsSuc = isSuc; 22 | this.mBssid = bssid; 23 | this.mInetAddress = inetAddress; 24 | this.mIsCancelled = new AtomicBoolean(false); 25 | } 26 | 27 | @Override 28 | public boolean isSuc() { 29 | return this.mIsSuc; 30 | } 31 | 32 | @Override 33 | public String getBssid() { 34 | return this.mBssid; 35 | } 36 | 37 | @Override 38 | public boolean isCancelled() { 39 | return mIsCancelled.get(); 40 | } 41 | 42 | public void setIsCancelled(boolean isCancelled){ 43 | this.mIsCancelled.set(isCancelled); 44 | } 45 | 46 | @Override 47 | public InetAddress getInetAddress() { 48 | return this.mInetAddress; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /res/drawable/spinner_background_ab_esp8266iot.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 23 | 25 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /res/layout/db_edit_name_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 38 | 39 | -------------------------------------------------------------------------------- /res/drawable/progress_horizontal_esp8266iot.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /ESPRESSIF MIT LICENSE V1.LICENSE: -------------------------------------------------------------------------------- 1 | ESPRSSIF MIT License 2 | 3 | Copyright © 2015 4 | 5 | Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, it is free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | 乐鑫 MIT 许可证 12 | 13 | 版权 © 2015 <乐鑫信息科技(上海)有限公司> 14 | 15 | 该许可证授权仅限于乐鑫信息科技 ESP8266 产品的应用开发。在此情况下,该许可证免费 授权任何获得该软件及其相关文档(统称为“软件”)的人无限制地经营该软件,包括无限制 的使用、复制、修改、合并、出版发行、散布、再授权、及贩售软件及软件副本的权利。被 授权人在享受这些权利的同时,需服从下面的条件: 16 | 17 | 在软件和软件的所有副本中都必须包含以上的版权声明和授权声明。 18 | 19 | 该软件按本来的样子提供,没有任何明确或暗含的担保,包括但不仅限于关于试销性、适合 某一特定用途和非侵权的保证。作者和版权持有人在任何情况下均不就由软件或软件使用引 起的以合同形式、民事侵权或其它方式提出的任何索赔、损害或其它责任负责。 20 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/util/CRC16CCITT.java: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Compilation: javac CRC16CCITT.java 3 | * Execution: java CRC16CCITT s 4 | * Dependencies: 5 | * 6 | * Reads in a sequence of bytes and prints out its 16 bit 7 | * Cylcic Redundancy Check (CRC-CCIIT 0xFFFF). 8 | * 9 | * 1 + x + x^5 + x^12 + x^16 is irreducible polynomial. 10 | * 11 | * % java CRC16-CCITT 123456789 12 | * CRC16-CCITT = 29b1 13 | * 14 | *************************************************************************/ 15 | package com.espressif.esp8266_iot.util; 16 | 17 | import android.util.Log; 18 | 19 | import android.util.Log; 20 | 21 | public class CRC16CCITT { 22 | 23 | static final String TAG = "esp8266"; 24 | 25 | // *************************************************************************** 26 | static public int CRC16(byte buf[], int len) { 27 | int crc = 0xFFFF; 28 | 29 | for (int pos = 0; pos < len; pos++) { 30 | crc ^= buf[pos] & 0xff; // XOR byte into least sig. byte of crc 31 | 32 | for (int i = 8; i != 0; i--) { // Loop over each bit 33 | if ((crc & 0x0001) != 0) { // If the LSB is set 34 | crc >>= 1; // Shift right and XOR 0xA001 35 | crc ^= 0xA001; 36 | } else { // Else LSB is not set 37 | crc >>= 1; // Just shift right 38 | } 39 | } 40 | } 41 | 42 | return crc; 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/task/__IEsptouchTask.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.task; 2 | 3 | import com.espressif.esp8266_iot.IEsptouchResult; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * IEsptouchTask defined the task of esp8266_iot should offer. INTERVAL here means 9 | * the milliseconds of interval of the step. REPEAT here means the repeat times 10 | * of the step. 11 | * 12 | * @author afunx 13 | * 14 | */ 15 | public interface __IEsptouchTask { 16 | 17 | /** 18 | * Interrupt the Esptouch Task when User tap back or close the Application. 19 | */ 20 | void interrupt(); 21 | 22 | /** 23 | * Note: !!!Don't call the task at UI EsptouchDemoActivity Thread or RuntimeException will 24 | * be thrown Execute the Esptouch Task and return the result 25 | * 26 | * @return the IEsptouchResult 27 | * @throws RuntimeException 28 | */ 29 | IEsptouchResult executeForResult() throws RuntimeException; 30 | 31 | /** 32 | * Note: !!!Don't call the task at UI EsptouchDemoActivity Thread or RuntimeException will 33 | * be thrown Execute the Esptouch Task and return the result 34 | * 35 | * @param expectTaskResultCount 36 | * the expect result count(if expectTaskResultCount <= 0, 37 | * expectTaskResultCount = Integer.MAX_VALUE) 38 | * @return the list of IEsptouchResult 39 | * @throws RuntimeException 40 | */ 41 | List executeForResults(int expectTaskResultCount) throws RuntimeException; 42 | 43 | /** 44 | * Turn on or off the log. 45 | */ 46 | static final boolean DEBUG = true; 47 | 48 | boolean isCancelled(); 49 | } 50 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/util/CRC8.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.util; 2 | 3 | import java.util.zip.Checksum; 4 | 5 | public class CRC8 implements Checksum { 6 | 7 | private final short init; 8 | 9 | private static final short[] crcTable = new short[256]; 10 | 11 | private short value; 12 | 13 | private static final short CRC_POLYNOM = 0x8c; 14 | 15 | private static final short CRC_INITIAL = 0x00; 16 | 17 | static { 18 | for (int dividend = 0; dividend < 256; dividend++) { 19 | int remainder = dividend;// << 8; 20 | for (int bit = 0; bit < 8; ++bit) 21 | if ((remainder & 0x01) != 0) 22 | remainder = (remainder >>> 1) ^ CRC_POLYNOM; 23 | else 24 | remainder >>>= 1; 25 | crcTable[dividend] = (short) remainder; 26 | } 27 | } 28 | 29 | public CRC8() { 30 | this.value = this.init = CRC_INITIAL; 31 | } 32 | 33 | @Override 34 | public void update(byte[] buffer, int offset, int len) { 35 | for (int i = 0; i < len; i++) { 36 | int data = buffer[offset + i] ^ value; 37 | value = (short) (crcTable[data & 0xff] ^ (value << 8)); 38 | } 39 | } 40 | 41 | /** 42 | * Updates the current checksum with the specified array of bytes. 43 | * Equivalent to calling update(buffer, 0, buffer.length). 44 | * 45 | * @param buffer 46 | * the byte array to update the checksum with 47 | */ 48 | public void update(byte[] buffer) { 49 | update(buffer, 0, buffer.length); 50 | } 51 | 52 | @Override 53 | public void update(int b) { 54 | update(new byte[] { (byte) b }, 0, 1); 55 | } 56 | 57 | @Override 58 | public long getValue() { 59 | return value & 0xff; 60 | } 61 | 62 | @Override 63 | public void reset() { 64 | value = init; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 22 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/protocol/EsptouchGenerator.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.protocol; 2 | 3 | import com.espressif.esp8266_iot.task.IEsptouchGenerator; 4 | import com.espressif.esp8266_iot.util.ByteUtil; 5 | 6 | import java.net.InetAddress; 7 | 8 | public class EsptouchGenerator implements IEsptouchGenerator { 9 | 10 | private final byte[][] mGcBytes2; 11 | private final byte[][] mDcBytes2; 12 | 13 | /** 14 | * Constructor of EsptouchGenerator, it will cost some time(maybe a bit 15 | * much) 16 | * 17 | * @param apSsid 18 | * the Ap's ssid 19 | * @param apBssid 20 | * the Ap's bssid 21 | * @param apPassword 22 | * the Ap's password 23 | * @param inetAddress 24 | * the phone's or pad's local ip address allocated by Ap 25 | * @param isSsidHiden 26 | * whether the Ap's ssid is hidden 27 | */ 28 | public EsptouchGenerator(String apSsid, String apBssid, String apPassword, 29 | InetAddress inetAddress, boolean isSsidHiden) { 30 | // generate guide code 31 | GuideCode gc = new GuideCode(); 32 | char[] gcU81 = gc.getU8s(); 33 | mGcBytes2 = new byte[gcU81.length][]; 34 | 35 | for (int i = 0; i < mGcBytes2.length; i++) { 36 | mGcBytes2[i] = ByteUtil.genSpecBytes(gcU81[i]); 37 | } 38 | 39 | // generate data code 40 | DatumCode dc = new DatumCode(apSsid, apBssid, apPassword, inetAddress, 41 | isSsidHiden); 42 | char[] dcU81 = dc.getU8s(); 43 | mDcBytes2 = new byte[dcU81.length][]; 44 | 45 | for (int i = 0; i < mDcBytes2.length; i++) { 46 | mDcBytes2[i] = ByteUtil.genSpecBytes(dcU81[i]); 47 | } 48 | } 49 | 50 | @Override 51 | public byte[][] getGCBytes2() { 52 | return mGcBytes2; 53 | } 54 | 55 | @Override 56 | public byte[][] getDCBytes2() { 57 | return mDcBytes2; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/IEsptouchTask.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot; 2 | 3 | import java.util.List; 4 | 5 | public interface IEsptouchTask { 6 | 7 | /** 8 | * Interrupt the Esptouch Task when User tap back or close the Application. 9 | */ 10 | void interrupt(); 11 | 12 | /** 13 | * Note: !!!Don't call the task at UI EsptouchDemoActivity Thread or RuntimeException will 14 | * be thrown Execute the Esptouch Task and return the result 15 | * 16 | * Smart Config v2.2 support the API 17 | * 18 | * @return the IEsptouchResult 19 | * @throws RuntimeException 20 | */ 21 | IEsptouchResult executeForResult() throws RuntimeException; 22 | 23 | /** 24 | * Note: !!!Don't call the task at UI EsptouchDemoActivity Thread or RuntimeException will 25 | * be thrown Execute the Esptouch Task and return the result 26 | * 27 | * Smart Config v2.2 support the API 28 | * 29 | * It will be blocked until the client receive result count >= expectTaskResultCount. 30 | * If it fail, it will return one fail result will be returned in the list. 31 | * If it is cancelled while executing, 32 | * if it has received some results, all of them will be returned in the list. 33 | * if it hasn't received any results, one cancel result will be returned in the list. 34 | * 35 | * @param expectTaskResultCount 36 | * the expect result count(if expectTaskResultCount <= 0, 37 | * expectTaskResultCount = Integer.MAX_VALUE) 38 | * @return the list of IEsptouchResult 39 | * @throws RuntimeException 40 | */ 41 | List executeForResults(int expectTaskResultCount) throws RuntimeException; 42 | 43 | /** 44 | * check whether the task is cancelled by user 45 | * 46 | * @return whether the task is cancelled by user 47 | */ 48 | boolean isCancelled(); 49 | } 50 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 23 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 38 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/activitys/EspWifiAdminSimple.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.activitys; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | import android.net.NetworkInfo; 6 | import android.net.wifi.WifiInfo; 7 | import android.net.wifi.WifiManager; 8 | 9 | public class EspWifiAdminSimple { 10 | 11 | private final Context mContext; 12 | 13 | 14 | public EspWifiAdminSimple(Context context) { 15 | mContext = context; 16 | } 17 | 18 | public String getWifiConnectedSsid() { 19 | WifiInfo mWifiInfo = getConnectionInfo(); 20 | String ssid = null; 21 | if (mWifiInfo != null && isWifiConnected()) { 22 | int len = mWifiInfo.getSSID().length(); 23 | if (mWifiInfo.getSSID().startsWith("\"") 24 | && mWifiInfo.getSSID().endsWith("\"")) { 25 | ssid = mWifiInfo.getSSID().substring(1, len - 1); 26 | } else { 27 | ssid = mWifiInfo.getSSID(); 28 | } 29 | 30 | } 31 | return ssid; 32 | } 33 | 34 | public String getWifiConnectedBssid() { 35 | WifiInfo mWifiInfo = getConnectionInfo(); 36 | String bssid = null; 37 | if (mWifiInfo != null && isWifiConnected()) { 38 | bssid = mWifiInfo.getBSSID(); 39 | } 40 | return bssid; 41 | } 42 | 43 | // get the wifi info which is "connected" in wifi-setting 44 | private WifiInfo getConnectionInfo() { 45 | WifiManager mWifiManager = (WifiManager) mContext 46 | .getSystemService(Context.WIFI_SERVICE); 47 | WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); 48 | return wifiInfo; 49 | } 50 | 51 | private boolean isWifiConnected() { 52 | NetworkInfo mWiFiNetworkInfo = getWifiNetworkInfo(); 53 | boolean isWifiConnected = false; 54 | if (mWiFiNetworkInfo != null) { 55 | isWifiConnected = mWiFiNetworkInfo.isConnected(); 56 | } 57 | return isWifiConnected; 58 | } 59 | 60 | private NetworkInfo getWifiNetworkInfo() { 61 | ConnectivityManager mConnectivityManager = (ConnectivityManager) mContext 62 | .getSystemService(Context.CONNECTIVITY_SERVICE); 63 | NetworkInfo mWiFiNetworkInfo = mConnectivityManager 64 | .getNetworkInfo(ConnectivityManager.TYPE_WIFI); 65 | return mWiFiNetworkInfo; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ESP8266-IOT 5 | Settings 6 | Hello world! 7 | Version 0.0.4 Enthält Sourcecode der Fa. Expressif 8 | SSID: 9 | Password: 10 | SSID versteckt: 11 | Task result count 12 | Fertig 13 | Scan 14 | Setup 15 | Save 16 | Scan 17 | 18 | Einrichtung
20 | SSID:
Hier wird Ihnen die Kennung des AP (Routers) mitgeteilt.

21 | Passwort:
Geben Sie hier das Passwort des AP (Routers) an.


22 | Wenn die SSID im AP als \"Versteckt\" eingerichtet ist stellen sie den Schalter auf \"An\". 23 | ]]> 24 |
25 | MQTT IP 26 | 192.168.178.5 27 | MQTT Port 28 | 1883 29 | MQTT User 30 | 31 | MQTT Pass 32 | 33 | MQTT SSL 34 | Upgrade IP 35 | 84.200.150.145 36 | Port 37 | 80 38 | Send\nto all 39 | to all 40 | 41 | Impulslänge 42 | 1000 43 | 44 | Version 45 |
46 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/util/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.util; 2 | 3 | /** 4 | * Created on 20.07.15 5 | * http://www.hrupin.com/2011/10/how-to-finish-all-activities-in-your-android-application-through-simple-call 6 | */ 7 | import android.app.Activity; 8 | import android.content.BroadcastReceiver; 9 | import android.content.Context; 10 | import android.content.Intent; 11 | import android.content.IntentFilter; 12 | 13 | public abstract class BaseActivity extends Activity { 14 | public static final String FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION = "com.espressif.esp8266_iot.activitys.FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION"; 15 | private BaseActivityReceiver baseActivityReceiver = new BaseActivityReceiver(); 16 | public static final IntentFilter INTENT_FILTER = createIntentFilter(); 17 | 18 | //********************************************************************************************** 19 | private static IntentFilter createIntentFilter(){ 20 | IntentFilter filter = new IntentFilter(); 21 | filter.addAction(FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION); 22 | return filter; 23 | } 24 | //********************************************************************************************** 25 | protected void registerBaseActivityReceiver() { 26 | registerReceiver(baseActivityReceiver, INTENT_FILTER); 27 | } 28 | //********************************************************************************************** 29 | protected void unRegisterBaseActivityReceiver() { 30 | unregisterReceiver(baseActivityReceiver); 31 | } 32 | //********************************************************************************************** 33 | public class BaseActivityReceiver extends BroadcastReceiver{ 34 | @Override 35 | public void onReceive(Context context, Intent intent) { 36 | if(intent.getAction().equals(FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION)){ 37 | finish(); 38 | } 39 | } 40 | } 41 | //********************************************************************************************** 42 | protected void closeAllActivities(){ 43 | sendBroadcast(new Intent(FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION)); 44 | } 45 | } -------------------------------------------------------------------------------- /res/drawable/tab_indicator_ab_esp8266iot.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/EsptouchTask.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot; 2 | 3 | import android.content.Context; 4 | 5 | import com.espressif.esp8266_iot.task.EsptouchTaskParameter; 6 | import com.espressif.esp8266_iot.task.IEsptouchTaskParameter; 7 | import com.espressif.esp8266_iot.task.__EsptouchTask; 8 | 9 | import java.util.List; 10 | 11 | 12 | public class EsptouchTask implements IEsptouchTask { 13 | 14 | public __EsptouchTask _mEsptouchTask; 15 | private IEsptouchTaskParameter _mParameter; 16 | 17 | /** 18 | * Constructor of EsptouchTask 19 | * 20 | * @param apSsid 21 | * the Ap's ssid 22 | * @param apBssid 23 | * the Ap's bssid 24 | * @param apPassword 25 | * the Ap's password 26 | * @param isSsidHidden 27 | * whether the Ap's ssid is hidden 28 | * @param context 29 | * the Context of the Application 30 | */ 31 | public EsptouchTask(String apSsid, String apBssid, String apPassword,boolean isSsidHidden, Context context) { 32 | _mParameter = new EsptouchTaskParameter(); 33 | _mEsptouchTask = new __EsptouchTask(apSsid, apBssid, apPassword, context, _mParameter, isSsidHidden); 34 | } 35 | 36 | /** 37 | * Constructor of EsptouchTask 38 | * 39 | * @param apSsid 40 | * the Ap's ssid 41 | * @param apBssid 42 | * the Ap's bssid 43 | * @param apPassword 44 | * the Ap's password 45 | * @param isSsidHidden 46 | * whether the Ap's ssid is hidden 47 | * @param timeoutMillisecond(it should be >= 10000+8000) 48 | * millisecond of total timeout 49 | * @param context 50 | * the Context of the Application 51 | */ 52 | public EsptouchTask(String apSsid, String apBssid, String apPassword,boolean isSsidHidden,int timeoutMillisecond, Context context) { 53 | _mParameter = new EsptouchTaskParameter(); 54 | _mParameter.setWaitUdpTotalMillisecond(timeoutMillisecond); 55 | _mEsptouchTask = new __EsptouchTask(apSsid, apBssid, apPassword, context, _mParameter, isSsidHidden); 56 | } 57 | 58 | 59 | @Override 60 | public void interrupt() { 61 | _mEsptouchTask.interrupt(); 62 | } 63 | 64 | @Override 65 | public IEsptouchResult executeForResult() throws RuntimeException { 66 | return _mEsptouchTask.executeForResult(); 67 | } 68 | 69 | @Override 70 | public boolean isCancelled() { 71 | return _mEsptouchTask.isCancelled(); 72 | } 73 | 74 | @Override 75 | public List executeForResults(int expectTaskResultCount) 76 | throws RuntimeException { 77 | if (expectTaskResultCount <= 0) { 78 | expectTaskResultCount = Integer.MAX_VALUE; 79 | } 80 | return _mEsptouchTask.executeForResults(expectTaskResultCount); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/util/EspNetUtil.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.util; 2 | 3 | import android.content.Context; 4 | import android.net.wifi.WifiInfo; 5 | import android.net.wifi.WifiManager; 6 | 7 | import java.net.InetAddress; 8 | import java.net.UnknownHostException; 9 | 10 | public class EspNetUtil { 11 | 12 | /** 13 | * get the local ip address by Android System 14 | * 15 | * @param context 16 | * the context 17 | * @return the local ip addr allocated by Ap 18 | */ 19 | public static InetAddress getLocalInetAddress(Context context) { 20 | WifiManager wm = (WifiManager) context 21 | .getSystemService(Context.WIFI_SERVICE); 22 | WifiInfo wifiInfo = wm.getConnectionInfo(); 23 | int localAddrInt = wifiInfo.getIpAddress(); 24 | String localAddrStr = __formatString(localAddrInt); 25 | InetAddress localInetAddr = null; 26 | try { 27 | localInetAddr = InetAddress.getByName(localAddrStr); 28 | } catch (UnknownHostException e) { 29 | e.printStackTrace(); 30 | } 31 | return localInetAddr; 32 | } 33 | 34 | private static String __formatString(int value) { 35 | String strValue = ""; 36 | byte[] ary = __intToByteArray(value); 37 | for (int i = ary.length - 1; i >= 0; i--) { 38 | strValue += (ary[i] & 0xFF); 39 | if (i > 0) { 40 | strValue += "."; 41 | } 42 | } 43 | return strValue; 44 | } 45 | 46 | private static byte[] __intToByteArray(int value) { 47 | byte[] b = new byte[4]; 48 | for (int i = 0; i < 4; i++) { 49 | int offset = (b.length - 1 - i) * 8; 50 | b[i] = (byte) ((value >>> offset) & 0xFF); 51 | } 52 | return b; 53 | } 54 | 55 | /** 56 | * parse InetAddress 57 | * 58 | * @param inetAddrBytes 59 | * @return 60 | */ 61 | public static InetAddress parseInetAddr(byte[] inetAddrBytes, int offset, 62 | int count) { 63 | InetAddress inetAddress = null; 64 | StringBuilder sb = new StringBuilder(); 65 | for (int i = 0; i < count; i++) { 66 | sb.append(Integer.toString(inetAddrBytes[offset + i] & 0xff)); 67 | if (i != count-1) { 68 | sb.append('.'); 69 | } 70 | } 71 | try { 72 | inetAddress = InetAddress.getByName(sb.toString()); 73 | } catch (UnknownHostException e) { 74 | e.printStackTrace(); 75 | } 76 | return inetAddress; 77 | } 78 | 79 | /** 80 | * parse bssid 81 | * 82 | * @param bssid the bssid 83 | * @return byte converted from bssid 84 | */ 85 | public static byte[] parseBssid2bytes(String bssid) { 86 | String bssidSplits[] = bssid.split(":"); 87 | byte[] result = new byte[bssidSplits.length]; 88 | for(int i = 0;i < bssidSplits.length; i++) { 89 | result[i] = (byte) Integer.parseInt(bssidSplits[i], 16); 90 | } 91 | return result; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/protocol/DataCode.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.protocol; 2 | 3 | import com.espressif.esp8266_iot.task.ICodeData; 4 | import com.espressif.esp8266_iot.util.ByteUtil; 5 | import com.espressif.esp8266_iot.util.CRC8; 6 | 7 | /** 8 | * one data format:(data code should have 2 to 65 data) 9 | * 10 | * control byte high 4 bits low 4 bits 11 | * 1st 9bits: 0x0 crc(high) data(high) 12 | * 2nd 9bits: 0x1 sequence header 13 | * 3rd 9bits: 0x0 crc(low) data(low) 14 | * 15 | * sequence header: 0,1,2,... 16 | * 17 | * @author afunx 18 | * 19 | */ 20 | public class DataCode implements ICodeData{ 21 | 22 | public static final int DATA_CODE_LEN = 6; 23 | 24 | private static final int INDEX_MAX = 127; 25 | 26 | private final byte mSeqHeader; 27 | private final byte mDataHigh; 28 | private final byte mDataLow; 29 | // the crc here means the crc of the data and sequence header be transformed 30 | // it is calculated by index and data to be transformed 31 | private final byte mCrcHigh; 32 | private final byte mCrcLow; 33 | 34 | /** 35 | * Constructor of DataCode 36 | * @param u8 the character to be transformed 37 | * @param index the index of the char 38 | */ 39 | public DataCode(char u8, int index) { 40 | if (index > INDEX_MAX) { 41 | throw new RuntimeException("index > INDEX_MAX"); 42 | } 43 | byte[] dataBytes = ByteUtil.splitUint8To2bytes(u8); 44 | mDataHigh = dataBytes[0]; 45 | mDataLow = dataBytes[1]; 46 | CRC8 crc8 = new CRC8(); 47 | crc8.update(ByteUtil.convertUint8toByte(u8)); 48 | crc8.update(index); 49 | byte[] crcBytes = ByteUtil.splitUint8To2bytes((char) crc8.getValue()); 50 | mCrcHigh = crcBytes[0]; 51 | mCrcLow = crcBytes[1]; 52 | mSeqHeader = (byte) index; 53 | } 54 | 55 | @Override 56 | public byte[] getBytes() { 57 | byte[] dataBytes = new byte[DATA_CODE_LEN]; 58 | dataBytes[0] = 0x00; 59 | dataBytes[1] = ByteUtil.combine2bytesToOne(mCrcHigh,mDataHigh); 60 | dataBytes[2] = 0x01; 61 | dataBytes[3] = mSeqHeader; 62 | dataBytes[4] = 0x00; 63 | dataBytes[5] = ByteUtil.combine2bytesToOne(mCrcLow, mDataLow); 64 | return dataBytes; 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | StringBuilder sb = new StringBuilder(); 70 | byte[] dataBytes = getBytes(); 71 | for (int i = 0; i < DATA_CODE_LEN; i++) { 72 | String hexString = ByteUtil.convertByte2HexString(dataBytes[i]); 73 | sb.append("0x"); 74 | if (hexString.length() == 1) { 75 | sb.append("0"); 76 | } 77 | sb.append(hexString).append(" "); 78 | } 79 | return sb.toString(); 80 | } 81 | 82 | @Override 83 | public char[] getU8s() { 84 | throw new RuntimeException("DataCode don't support getU8s()"); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 66 | 68 | -------------------------------------------------------------------------------- /src/net/shikii/widgets/SAutoBgButton.java: -------------------------------------------------------------------------------- 1 | package net.shikii.widgets; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.graphics.ColorFilter; 6 | import android.graphics.LightingColorFilter; 7 | import android.graphics.drawable.Drawable; 8 | import android.graphics.drawable.LayerDrawable; 9 | import android.util.AttributeSet; 10 | import android.widget.Button; 11 | 12 | /** 13 | * Applies a pressed state color filter or disabled state alpha for the button's background 14 | * drawable. 15 | * 16 | * @author shiki 17 | */ 18 | public class SAutoBgButton extends Button { 19 | 20 | public SAutoBgButton(Context context) { 21 | super(context); 22 | } 23 | 24 | public SAutoBgButton(Context context, AttributeSet attrs) { 25 | super(context, attrs); 26 | } 27 | 28 | public SAutoBgButton(Context context, AttributeSet attrs, int defStyle) { 29 | super(context, attrs, defStyle); 30 | } 31 | 32 | @SuppressWarnings("deprecation") 33 | @Override 34 | public void setBackgroundDrawable(Drawable d) { 35 | // Replace the original background drawable (e.g. image) with a LayerDrawable that 36 | // contains the original drawable. 37 | SAutoBgButtonBackgroundDrawable layer = new SAutoBgButtonBackgroundDrawable(d); 38 | super.setBackgroundDrawable(layer); 39 | } 40 | /* 41 | @Override 42 | public void setBackground(Drawable d) { 43 | // Replace the original background drawable (e.g. image) with a LayerDrawable that 44 | // contains the original drawable. 45 | SAutoBgButtonBackgroundDrawable layer = new SAutoBgButtonBackgroundDrawable(d); 46 | super.setBackground(layer); 47 | } 48 | */ 49 | /** 50 | * The stateful LayerDrawable used by this button. 51 | */ 52 | protected class SAutoBgButtonBackgroundDrawable extends LayerDrawable { 53 | 54 | // The color filter to apply when the button is pressed 55 | protected ColorFilter _pressedFilter = new LightingColorFilter(Color.LTGRAY, 1); 56 | // Alpha value when the button is disabled 57 | protected int _disabledAlpha = 100; 58 | // Alpha value when the button is enabled 59 | protected int _fullAlpha = 255; 60 | 61 | public SAutoBgButtonBackgroundDrawable(Drawable d) { 62 | super(new Drawable[] { d }); 63 | } 64 | 65 | @Override 66 | protected boolean onStateChange(int[] states) { 67 | boolean enabled = false; 68 | boolean pressed = false; 69 | 70 | for (int state : states) { 71 | if (state == android.R.attr.state_enabled) 72 | enabled = true; 73 | else if (state == android.R.attr.state_pressed) 74 | pressed = true; 75 | } 76 | 77 | mutate(); 78 | if (enabled && pressed) { 79 | setColorFilter(_pressedFilter); 80 | } else if (!enabled) { 81 | setColorFilter(null); 82 | setAlpha(_disabledAlpha); 83 | } else { 84 | setColorFilter(null); 85 | setAlpha(_fullAlpha); 86 | } 87 | 88 | invalidateSelf(); 89 | 90 | return super.onStateChange(states); 91 | } 92 | 93 | @Override 94 | public boolean isStateful() { 95 | return true; 96 | } 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/DataStore/DataStore_Data.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.DataStore; 2 | 3 | /** 4 | * Created by gerry on 22.07.2015. 5 | */ 6 | public class DataStore_Data { 7 | 8 | //private variables 9 | int _id; 10 | String _address; 11 | String _devid; 12 | String _function; 13 | String _status; 14 | Integer _isActive; 15 | 16 | // Empty constructor 17 | public DataStore_Data() { 18 | 19 | } 20 | 21 | public DataStore_Data(int id) { 22 | this._id = id; 23 | } 24 | 25 | public DataStore_Data(int id, String address, String _function, String _status, Integer _isActive) { 26 | this._id = id; 27 | this._address = address; 28 | this._function = _function; 29 | this._status = _status; 30 | this._isActive = _isActive; 31 | } 32 | 33 | public DataStore_Data(int id, String devid, String address, String _function, String _status, Integer _isActive) { 34 | this._id = id; 35 | this._devid = devid; 36 | this._address = address; 37 | this._function = _function; 38 | this._status = _status; 39 | this._isActive = _isActive; 40 | } 41 | 42 | //**************************************************************** 43 | // getting ID 44 | public int getID() { return this._id; } 45 | //**************************************************************** 46 | // setting id 47 | public void setID(int Value) { this._id = Value; } 48 | //**************************************************************** 49 | // getting Device ID 50 | public String getDevID() { return this._devid; } 51 | //**************************************************************** 52 | // setting Device id 53 | public void setDevID(String Value) { this._devid = Value; } 54 | //**************************************************************** 55 | // getting address 56 | public String getAddress() { 57 | return this._address; 58 | } 59 | //**************************************************************** 60 | // setting address 61 | public void setAddress(String Value) { 62 | this._address = Value; 63 | } 64 | //**************************************************************** 65 | // getting funtion 66 | public String getFunction() { 67 | return this._function; 68 | } 69 | //**************************************************************** 70 | // setting funtion 71 | public void setFunktion(String Value) { 72 | this._function = Value; 73 | } 74 | //**************************************************************** 75 | // getting status 76 | public String getStatus() { return this._status; } 77 | //**************************************************************** 78 | // setting status 79 | public void setStatus(String Value) { 80 | this._status = Value; 81 | } 82 | //**************************************************************** 83 | // getting active 84 | public Integer getisActive() { 85 | return this._isActive; 86 | } 87 | //**************************************************************** 88 | // setting active 89 | public void setisActive(Integer Value) { 90 | this._isActive = Value; 91 | } 92 | } -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/udp/UDPListenerService.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.udp; 2 | import java.net.DatagramPacket; 3 | import java.net.DatagramSocket; 4 | import java.net.InetAddress; 5 | import java.net.SocketTimeoutException; 6 | import java.net.UnknownHostException; 7 | 8 | import org.apache.http.util.ExceptionUtils; 9 | 10 | import android.app.Service; 11 | import android.content.Intent; 12 | import android.os.IBinder; 13 | import android.util.Log; 14 | import android.widget.Toast; 15 | 16 | 17 | /* 18 | * Linux command to send UDP: 19 | * #socat - UDP-DATAGRAM:192.168.1.255:11111,broadcast,sp=11111 20 | * 21 | * Programm 22 | * my = new UDPListenerService(); 23 | * my.onStartCommand(getIntent(),0,0); 24 | 25 | */ 26 | public class UDPListenerService extends Service { 27 | private static final String TAG = "UDPListenerService"; 28 | static String UDP_BROADCAST = "UDPBroadcast"; 29 | 30 | //Boolean shouldListenForUDPBroadcast = false; 31 | DatagramSocket socket; 32 | 33 | private void listenAndWaitAndThrowIntent(InetAddress broadcastIP, Integer port) throws Exception { 34 | byte[] recvBuf = new byte[15000]; 35 | if (socket == null || socket.isClosed()) { 36 | socket = new DatagramSocket(port, broadcastIP); 37 | socket.setBroadcast(true); 38 | } 39 | //socket.setSoTimeout(1000); 40 | DatagramPacket packet = new DatagramPacket(recvBuf, recvBuf.length); 41 | Log.d(TAG, "Waiting for UDP broadcast"); 42 | socket.receive(packet); 43 | 44 | String senderIP = packet.getAddress().getHostAddress(); 45 | String message = new String(packet.getData()).trim(); 46 | 47 | Log.d(TAG, "Got UDB broadcast from " + senderIP + ", message: " + message); 48 | 49 | broadcastIntent(senderIP, message); 50 | socket.close(); 51 | } 52 | 53 | private void broadcastIntent(String senderIP, String message) { 54 | /* 55 | Intent intent = new Intent(UDPListenerService.UDP_BROADCAST); 56 | intent.putExtra("sender", senderIP); 57 | intent.putExtra("message", message); 58 | sendBroadcast(intent); 59 | */ 60 | } 61 | 62 | Thread UDPBroadcastThread; 63 | 64 | void startListenForUDPBroadcast() { 65 | UDPBroadcastThread = new Thread(new Runnable() { 66 | public void run() { 67 | try { 68 | InetAddress broadcastIP = InetAddress.getByName("192.168.178.255"); //172.16.238.42 //192.168.1.255 69 | Integer port = 18266; 70 | while (shouldRestartSocketListen) { 71 | listenAndWaitAndThrowIntent(broadcastIP, port); 72 | } 73 | //if (!shouldListenForUDPBroadcast) throw new ThreadDeath(); 74 | } catch (Exception e) { 75 | Log.e(TAG, "no longer listening for UDP broadcasts cause of error " + e.getMessage()); 76 | } 77 | } 78 | }); 79 | UDPBroadcastThread.start(); 80 | } 81 | 82 | private Boolean shouldRestartSocketListen=true; 83 | 84 | void stopListen() { 85 | Log.e(TAG, "stopListen"); 86 | shouldRestartSocketListen = false; 87 | socket.close(); 88 | } 89 | 90 | @Override 91 | public void onCreate() { 92 | 93 | }; 94 | 95 | @Override 96 | public void onDestroy() { 97 | stopListen(); 98 | } 99 | 100 | 101 | @Override 102 | public int onStartCommand(Intent intent, int flags, int startId) { 103 | shouldRestartSocketListen = true; 104 | startListenForUDPBroadcast(); 105 | Log.d(TAG, "Service started"); 106 | return START_STICKY; 107 | } 108 | 109 | @Override 110 | public IBinder onBind(Intent intent) { 111 | return null; 112 | } 113 | 114 | } -------------------------------------------------------------------------------- /.idea/codeStyleSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 72 | 74 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/task/IEsptouchTaskParameter.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.task; 2 | 3 | public interface IEsptouchTaskParameter { 4 | 5 | /** 6 | * get interval millisecond for guide code(the time between each guide code sending) 7 | * @return interval millisecond for guide code(the time between each guide code sending) 8 | */ 9 | long getIntervalGuideCodeMillisecond(); 10 | 11 | /** 12 | * get interval millisecond for data code(the time between each data code sending) 13 | * @return interval millisecond for data code(the time between each data code sending) 14 | */ 15 | long getIntervalDataCodeMillisecond(); 16 | 17 | /** 18 | * get timeout millisecond for guide code(the time how much the guide code sending) 19 | * @return timeout millisecond for guide code(the time how much the guide code sending) 20 | */ 21 | long getTimeoutGuideCodeMillisecond(); 22 | 23 | /** 24 | * get timeout millisecond for data code(the time how much the data code sending) 25 | * @return timeout millisecond for data code(the time how much the data code sending) 26 | */ 27 | long getTimeoutDataCodeMillisecond(); 28 | 29 | /** 30 | * get timeout millisecond for total code(guide code and data code altogether) 31 | * @return timeout millisecond for total code(guide code and data code altogether) 32 | */ 33 | long getTimeoutTotalCodeMillisecond(); 34 | 35 | /** 36 | * get total repeat time for executing esp8266_iot task 37 | * @return total repeat time for executing esp8266_iot task 38 | */ 39 | int getTotalRepeatTime(); 40 | 41 | /** 42 | * the length of the Esptouch result 1st byte is the total length of ssid and 43 | * password, the other 6 bytes are the device's bssid 44 | */ 45 | 46 | /** 47 | * get esptouchResult length of one 48 | * @return length of one 49 | */ 50 | int getEsptouchResultOneLen(); 51 | 52 | /** 53 | * get esptouchResult length of mac 54 | * @return length of mac 55 | */ 56 | int getEsptouchResultMacLen(); 57 | 58 | /** 59 | * get esptouchResult length of ip 60 | * @return length of ip 61 | */ 62 | int getEsptouchResultIpLen(); 63 | 64 | /** 65 | * get esptouchResult total length 66 | * @return total length 67 | */ 68 | int getEsptouchResultTotalLen(); 69 | 70 | /** 71 | * get port for listening(used by server) 72 | * @return port for listening(used by server) 73 | */ 74 | int getPortListening(); 75 | 76 | /** 77 | * get target hostname 78 | * @return target hostame(used by client) 79 | */ 80 | String getTargetHostname(); 81 | 82 | /** 83 | * get target port 84 | * @return target port(used by client) 85 | */ 86 | int getTargetPort(); 87 | 88 | /** 89 | * get millisecond for waiting udp receiving(receiving without sending) 90 | * @return millisecond for waiting udp receiving(receiving without sending) 91 | */ 92 | int getWaitUdpReceivingMillisecond(); 93 | 94 | /** 95 | * get millisecond for waiting udp sending(sending including receiving) 96 | * @return millisecond for waiting udep sending(sending including receiving) 97 | */ 98 | int getWaitUdpSendingMillisecond(); 99 | 100 | /** 101 | * get millisecond for waiting udp sending and receiving 102 | * @return millisecond for waiting udp sending and receiving 103 | */ 104 | int getWaitUdpTotalMillisecond(); 105 | 106 | /** 107 | * get the threshold for how many correct broadcast should be received 108 | * @return the threshold for how many correct broadcast should be received 109 | */ 110 | int getThresholdSucBroadcastCount(); 111 | 112 | /** 113 | * set the millisecond for waiting udp sending and receiving 114 | * @param waitUdpTotalMillisecond the millisecond for waiting udp sending and receiving 115 | */ 116 | void setWaitUdpTotalMillisecond(int waitUdpTotalMillisecond); 117 | 118 | /** 119 | * get the count of expect task results 120 | * @return the count of expect task results 121 | */ 122 | int getExpectTaskResultCount(); 123 | 124 | /** 125 | * set the count of expect task results 126 | * @param expectTaskResultCount the count of expect task results 127 | */ 128 | void setExpectTaskResultCount(int expectTaskResultCount); 129 | } 130 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/udp/UDPSocketClient.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.udp; 2 | 3 | import android.util.Log; 4 | 5 | import com.espressif.esp8266_iot.task.__IEsptouchTask; 6 | 7 | import java.io.IOException; 8 | import java.net.DatagramPacket; 9 | import java.net.DatagramSocket; 10 | import java.net.InetAddress; 11 | import java.net.SocketException; 12 | import java.net.UnknownHostException; 13 | 14 | /** 15 | * this class is used to help send UDP data according to length 16 | * 17 | * @author afunx 18 | * 19 | */ 20 | public class UDPSocketClient { 21 | 22 | private static final String TAG = "UDPSocketClient"; 23 | private DatagramSocket mSocket; 24 | private volatile boolean mIsStop; 25 | private volatile boolean mIsClosed; 26 | 27 | public UDPSocketClient() { 28 | try { 29 | this.mSocket = new DatagramSocket(); 30 | this.mIsStop = false; 31 | this.mIsClosed = false; 32 | } catch (SocketException e) { 33 | if (__IEsptouchTask.DEBUG) { 34 | Log.e(TAG, "SocketException"); 35 | } 36 | e.printStackTrace(); 37 | } 38 | } 39 | 40 | @Override 41 | protected void finalize() throws Throwable { 42 | close(); 43 | super.finalize(); 44 | } 45 | 46 | public void interrupt() { 47 | if (__IEsptouchTask.DEBUG) { 48 | Log.i(TAG, "USPSocketClient is interrupt"); 49 | } 50 | this.mIsStop = true; 51 | } 52 | 53 | /** 54 | * close the UDP socket 55 | */ 56 | public synchronized void close() { 57 | if (!this.mIsClosed) { 58 | this.mSocket.close(); 59 | this.mIsClosed = true; 60 | } 61 | } 62 | 63 | /** 64 | * send the data by UDP 65 | * 66 | * @param data 67 | * the data to be sent 68 | * @param targetHostName 69 | * the host name of target, e.g. 192.168.1.101 70 | * @param targetPort 71 | * the port of target 72 | * @param interval 73 | * the milliseconds to between each UDP sent 74 | */ 75 | public void sendData(byte[][] data, String targetHostName, int targetPort, 76 | long interval) { 77 | sendData(data, 0, data.length, targetHostName, targetPort, interval); 78 | } 79 | 80 | 81 | /** 82 | * send the data by UDP 83 | * 84 | * @param data 85 | * the data to be sent 86 | * @param offset 87 | * the offset which data to be sent 88 | * @param count 89 | * the count of the data 90 | * @param targetHostName 91 | * the host name of target, e.g. 192.168.1.101 92 | * @param targetPort 93 | * the port of target 94 | * @param interval 95 | * the milliseconds to between each UDP sent 96 | */ 97 | public void sendData(byte[][] data, int offset, int count, 98 | String targetHostName, int targetPort, long interval) { 99 | if ((data == null) || (data.length <= 0)) { 100 | if (__IEsptouchTask.DEBUG) { 101 | Log.e(TAG, "sendData(): data == null or length <= 0"); 102 | } 103 | return; 104 | } 105 | for (int i = offset; !mIsStop && i < offset + count; i++) { 106 | if (data[i].length == 0) { 107 | continue; 108 | } 109 | try { 110 | // Log.i(TAG, "data[" + i + " +].length = " + data[i].length); 111 | DatagramPacket localDatagramPacket = new DatagramPacket( 112 | data[i], data[i].length, 113 | InetAddress.getByName(targetHostName), targetPort); 114 | this.mSocket.send(localDatagramPacket); 115 | } catch (UnknownHostException e) { 116 | if (__IEsptouchTask.DEBUG) { 117 | Log.e(TAG, "sendData(): UnknownHostException"); 118 | } 119 | e.printStackTrace(); 120 | mIsStop = true; 121 | break; 122 | } catch (IOException e) { 123 | if (__IEsptouchTask.DEBUG) { 124 | Log.e(TAG, "sendData(): IOException, but just ignore it"); 125 | } 126 | // for the Ap will make some troubles when the phone send too many UDP packets, 127 | // but we don't expect the UDP packet received by others, so just ignore it 128 | } 129 | try { 130 | Thread.sleep(interval); 131 | } catch (InterruptedException e) { 132 | e.printStackTrace(); 133 | if (__IEsptouchTask.DEBUG) { 134 | Log.e(TAG, "sendData is Interrupted"); 135 | } 136 | mIsStop = true; 137 | break; 138 | } 139 | } 140 | if (mIsStop) { 141 | close(); 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /res/values/styles_esp8266iot.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 24 | 25 | 38 | 39 | 45 | 46 | 50 | 51 | 54 | 55 | 58 | 59 | 62 | 63 | 68 | 69 | 72 | 73 | 76 | 77 | 78 | 82 | 83 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/task/EsptouchTaskParameter.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.task; 2 | 3 | public class EsptouchTaskParameter implements IEsptouchTaskParameter { 4 | 5 | private long mIntervalGuideCodeMillisecond; 6 | private long mIntervalDataCodeMillisecond; 7 | private long mTimeoutGuideCodeMillisecond; 8 | private long mTimeoutDataCodeMillisecond; 9 | private int mTotalRepeatTime; 10 | private int mEsptouchResultOneLen; 11 | private int mEsptouchResultMacLen; 12 | private int mEsptouchResultIpLen; 13 | private int mEsptouchResultTotalLen; 14 | private int mPortListening; 15 | private int mTargetPort; 16 | private int mWaitUdpReceivingMilliseond; 17 | private int mWaitUdpSendingMillisecond; 18 | private int mThresholdSucBroadcastCount; 19 | private int mExpectTaskResultCount; 20 | private static int _datagramCount = 0; 21 | 22 | public EsptouchTaskParameter() { 23 | mIntervalGuideCodeMillisecond = 10; 24 | mIntervalDataCodeMillisecond = 10; 25 | mTimeoutGuideCodeMillisecond = 2000; 26 | mTimeoutDataCodeMillisecond = 4000; 27 | mTotalRepeatTime = 1; 28 | mEsptouchResultOneLen = 1; 29 | mEsptouchResultMacLen = 6; 30 | mEsptouchResultIpLen = 4; 31 | mEsptouchResultTotalLen = 1 + 6 + 4; 32 | mPortListening = 18266; 33 | mTargetPort = 7001; 34 | mWaitUdpReceivingMilliseond = 15000; 35 | mWaitUdpSendingMillisecond = 45000; 36 | mThresholdSucBroadcastCount = 1; 37 | mExpectTaskResultCount = 1; 38 | } 39 | 40 | // the range of the result should be 1-100 41 | private static int __getNextDatagramCount() { 42 | return 1 + (_datagramCount++) % 100; 43 | } 44 | 45 | @Override 46 | public long getIntervalGuideCodeMillisecond() { 47 | return mIntervalGuideCodeMillisecond; 48 | } 49 | 50 | @Override 51 | public long getIntervalDataCodeMillisecond() { 52 | return mIntervalDataCodeMillisecond; 53 | } 54 | 55 | @Override 56 | public long getTimeoutGuideCodeMillisecond() { 57 | return mTimeoutGuideCodeMillisecond; 58 | } 59 | 60 | @Override 61 | public long getTimeoutDataCodeMillisecond() { 62 | return mTimeoutDataCodeMillisecond; 63 | } 64 | 65 | @Override 66 | public long getTimeoutTotalCodeMillisecond() { 67 | return mTimeoutGuideCodeMillisecond + mTimeoutDataCodeMillisecond; 68 | } 69 | 70 | @Override 71 | public int getTotalRepeatTime() { 72 | return mTotalRepeatTime; 73 | } 74 | 75 | @Override 76 | public int getEsptouchResultOneLen() { 77 | return mEsptouchResultOneLen; 78 | } 79 | 80 | @Override 81 | public int getEsptouchResultMacLen() { 82 | return mEsptouchResultMacLen; 83 | } 84 | 85 | @Override 86 | public int getEsptouchResultIpLen() { 87 | return mEsptouchResultIpLen; 88 | } 89 | 90 | @Override 91 | public int getEsptouchResultTotalLen() { 92 | return mEsptouchResultTotalLen; 93 | } 94 | 95 | @Override 96 | public int getPortListening() { 97 | return mPortListening; 98 | } 99 | 100 | // target hostname is : 234.1.1.1, 234.2.2.2, 234.3.3.3 to 234.100.100.100 101 | @Override 102 | public String getTargetHostname() { 103 | int count = __getNextDatagramCount(); 104 | return "234." + count + "." + count + "." + count; 105 | } 106 | 107 | @Override 108 | public int getTargetPort() { 109 | return mTargetPort; 110 | } 111 | 112 | @Override 113 | public int getWaitUdpReceivingMillisecond() { 114 | return mWaitUdpReceivingMilliseond; 115 | } 116 | 117 | @Override 118 | public int getWaitUdpSendingMillisecond() { 119 | return mWaitUdpSendingMillisecond; 120 | } 121 | 122 | @Override 123 | public int getWaitUdpTotalMillisecond() { 124 | return mWaitUdpReceivingMilliseond + mWaitUdpSendingMillisecond; 125 | } 126 | 127 | @Override 128 | public int getThresholdSucBroadcastCount() { 129 | return mThresholdSucBroadcastCount; 130 | } 131 | 132 | @Override 133 | public void setWaitUdpTotalMillisecond(int waitUdpTotalMillisecond) { 134 | if (waitUdpTotalMillisecond < mWaitUdpReceivingMilliseond 135 | + getTimeoutTotalCodeMillisecond()) { 136 | // if it happen, even one turn about sending udp broadcast can't be 137 | // completed 138 | throw new IllegalArgumentException( 139 | "waitUdpTotalMillisecod is invalid, " 140 | + "it is less than mWaitUdpReceivingMilliseond + getTimeoutTotalCodeMillisecond()"); 141 | } 142 | mWaitUdpSendingMillisecond = waitUdpTotalMillisecond 143 | - mWaitUdpReceivingMilliseond; 144 | } 145 | 146 | @Override 147 | public int getExpectTaskResultCount() { 148 | return this.mExpectTaskResultCount; 149 | } 150 | 151 | @Override 152 | public void setExpectTaskResultCount(int expectTaskResultCount) { 153 | this.mExpectTaskResultCount = expectTaskResultCount; 154 | } 155 | 156 | } 157 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/udp/UDPSocketServer.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.udp; 2 | 3 | import android.content.Context; 4 | import android.net.wifi.WifiManager; 5 | import android.util.Log; 6 | 7 | import java.io.IOException; 8 | import java.net.DatagramPacket; 9 | import java.net.DatagramSocket; 10 | import java.net.InetSocketAddress; 11 | import java.net.SocketException; 12 | import java.util.Arrays; 13 | 14 | public class UDPSocketServer { 15 | 16 | private static final String TAG = "UDPSocketServer"; 17 | 18 | private DatagramPacket mReceivePacket; 19 | private DatagramSocket mServerSocket; 20 | private Context mContext; 21 | private WifiManager.MulticastLock mLock; 22 | private final byte[] buffer; 23 | private volatile boolean mIsClosed; 24 | 25 | private synchronized void acquireLock() { 26 | if (mLock != null && !mLock.isHeld()) { 27 | mLock.acquire(); 28 | } 29 | } 30 | 31 | private synchronized void releaseLock() { 32 | if (mLock != null && mLock.isHeld()) { 33 | try { 34 | mLock.release(); 35 | } catch (Throwable th) { 36 | // ignoring this exception, probably wakeLock was already released 37 | } 38 | } 39 | } 40 | 41 | /** 42 | * Constructor of UDP Socket Server 43 | * 44 | * @param port 45 | * the Socket Server port 46 | * @param socketTimeout 47 | * the socket read timeout 48 | * @param context 49 | * the context of the Application 50 | */ 51 | public UDPSocketServer(int port, int socketTimeout, Context context) { 52 | this.mContext = context; 53 | this.buffer = new byte[64]; 54 | this.mReceivePacket = new DatagramPacket(buffer, 64); 55 | try { 56 | WifiManager manager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); 57 | mLock = manager.createMulticastLock("test wifi"); 58 | this.mServerSocket = new DatagramSocket(port); 59 | //this.mServerSocket.setReuseAddress(true); 60 | //this.mServerSocket.bind(new InetSocketAddress(port)); // <-- now bind it 61 | this.mServerSocket.setSoTimeout(socketTimeout); 62 | this.mIsClosed = false; 63 | Log.d(TAG, "mServerSocket is created, socket read timeout: " 64 | + socketTimeout + ", port: " + port); 65 | } catch (IOException e) { 66 | Log.e(TAG, "IOException " + e.getMessage()); 67 | e.printStackTrace(); 68 | } 69 | } 70 | 71 | /** 72 | * Set the socket timeout in milliseconds 73 | * 74 | * @param timeout 75 | * the timeout in milliseconds or 0 for no timeout. 76 | * @return true whether the timeout is set suc 77 | */ 78 | public boolean setSoTimeout(int timeout) { 79 | try { 80 | this.mServerSocket.setSoTimeout(timeout); 81 | return true; 82 | } catch (SocketException e) { 83 | e.printStackTrace(); 84 | } 85 | return false; 86 | } 87 | 88 | /** 89 | * Receive one byte from the port and convert it into String 90 | * 91 | * @return 92 | */ 93 | public byte receiveOneByte() { 94 | Log.d(TAG, "receiveOneByte() entrance"); 95 | try { 96 | acquireLock(); 97 | mServerSocket.receive(mReceivePacket); 98 | Log.d(TAG, "receive: " + (0 + mReceivePacket.getData()[0])); 99 | return mReceivePacket.getData()[0]; 100 | } catch (IOException e) { 101 | e.printStackTrace(); 102 | } 103 | return Byte.MIN_VALUE; 104 | } 105 | 106 | /** 107 | * Receive specific length bytes from the port and convert it into String 108 | * 21,24,-2,52,-102,-93,-60 109 | * 15,18,fe,34,9a,a3,c4 110 | * @return 111 | */ 112 | public byte[] receiveSpecLenBytes(int len) { 113 | Log.d(TAG, "receiveSpecLenBytes() entrance: len = " + len); 114 | try { 115 | acquireLock(); 116 | mServerSocket.receive(mReceivePacket); 117 | byte[] recDatas = Arrays.copyOf(mReceivePacket.getData(), mReceivePacket.getLength()); 118 | Log.d(TAG, "received len : " + recDatas.length); 119 | for (int i = 0; i < recDatas.length; i++) { 120 | Log.e(TAG, "recDatas[" + i + "]:" + recDatas[i]); 121 | } 122 | Log.e(TAG, "receiveSpecLenBytes: " + new String(recDatas)); 123 | if (recDatas.length != len) { 124 | Log.w(TAG, 125 | "received len is different from specific len, return null"); 126 | return null; 127 | } 128 | return recDatas; 129 | } catch (IOException e) { 130 | e.printStackTrace(); 131 | } 132 | return null; 133 | } 134 | 135 | public void interrupt() { 136 | Log.i(TAG, "USPSocketServer is interrupt"); 137 | close(); 138 | } 139 | 140 | public synchronized void close() { 141 | if (!this.mIsClosed) { 142 | Log.e(TAG, "mServerSocket is closed"); 143 | mServerSocket.close(); 144 | releaseLock(); 145 | this.mIsClosed = true; 146 | } 147 | } 148 | 149 | @Override 150 | protected void finalize() throws Throwable { 151 | close(); 152 | super.finalize(); 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/protocol/DatumCode.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.protocol; 2 | 3 | import com.espressif.esp8266_iot.task.ICodeData; 4 | import com.espressif.esp8266_iot.util.ByteUtil; 5 | import com.espressif.esp8266_iot.util.CRC8; 6 | import com.espressif.esp8266_iot.util.EspNetUtil; 7 | 8 | import java.net.InetAddress; 9 | 10 | public class DatumCode implements ICodeData { 11 | 12 | // define by the Esptouch protocol, all of the datum code should add 1 at last to prevent 0 13 | private static final int EXTRA_LEN = 40; 14 | private static final int EXTRA_HEAD_LEN = 5; 15 | 16 | private final DataCode[] mDataCodes; 17 | 18 | /** 19 | * Constructor of DatumCode 20 | * @param apSsid the Ap's ssid 21 | * @param apBssid the Ap's bssid 22 | * @param apPassword the Ap's password 23 | * @param ipAddress the ip address of the phone or pad 24 | * @param isSsidHiden whether the Ap's ssid is hidden 25 | */ 26 | public DatumCode(String apSsid, String apBssid, String apPassword, 27 | InetAddress ipAddress, boolean isSsidHiden) { 28 | // Data = total len(1 byte) + apPwd len(1 byte) + SSID CRC(1 byte) + 29 | // BSSID CRC(1 byte) + TOTAL XOR(1 byte)+ ipAddress(4 byte) + apPwd + apSsid apPwdLen <= 30 | // 105 at the moment 31 | 32 | // total xor 33 | char totalXor = 0; 34 | 35 | char apPwdLen = (char) ByteUtil.getBytesByString(apPassword).length; 36 | CRC8 crc = new CRC8(); 37 | crc.update(ByteUtil.getBytesByString(apSsid)); 38 | char apSsidCrc = (char) crc.getValue(); 39 | 40 | crc.reset(); 41 | crc.update(EspNetUtil.parseBssid2bytes(apBssid)); 42 | char apBssidCrc = (char) crc.getValue(); 43 | 44 | char apSsidLen = (char) ByteUtil.getBytesByString(apSsid).length; 45 | // hostname parse 46 | String ipAddrStrs[] = ipAddress.getHostAddress().split("\\."); 47 | int ipLen = ipAddrStrs.length; 48 | 49 | char ipAddrChars[] = new char[ipLen]; 50 | // only support ipv4 at the moment 51 | for (int i = 0; i < ipLen; ++i) { 52 | ipAddrChars[i] = (char) Integer.parseInt(ipAddrStrs[i]); 53 | } 54 | 55 | 56 | char _totalLen = (char) (EXTRA_HEAD_LEN + ipLen + apPwdLen + apSsidLen); 57 | char totalLen = isSsidHiden ? (char) (EXTRA_HEAD_LEN + ipLen + apPwdLen + apSsidLen) 58 | : (char) (EXTRA_HEAD_LEN + ipLen + apPwdLen); 59 | 60 | // build data codes 61 | mDataCodes = new DataCode[totalLen]; 62 | mDataCodes[0] = new DataCode(_totalLen, 0); 63 | totalXor ^= _totalLen; 64 | mDataCodes[1] = new DataCode(apPwdLen, 1); 65 | totalXor ^= apPwdLen; 66 | mDataCodes[2] = new DataCode(apSsidCrc, 2); 67 | totalXor ^= apSsidCrc; 68 | mDataCodes[3] = new DataCode(apBssidCrc, 3); 69 | totalXor ^= apBssidCrc; 70 | mDataCodes[4] = null; 71 | for (int i = 0; i < ipLen; ++i) { 72 | mDataCodes[i + EXTRA_HEAD_LEN] = new DataCode(ipAddrChars[i], i + EXTRA_HEAD_LEN); 73 | totalXor ^= ipAddrChars[i]; 74 | } 75 | 76 | byte[] apPwdBytes = ByteUtil.getBytesByString(apPassword); 77 | char[] apPwdChars = new char[apPwdBytes.length]; 78 | for (int i = 0;i < apPwdBytes.length; i++) { 79 | apPwdChars[i] = ByteUtil.convertByte2Uint8(apPwdBytes[i]); 80 | } 81 | for (int i = 0; i < apPwdChars.length; i++) { 82 | mDataCodes[i + EXTRA_HEAD_LEN + ipLen] = new DataCode( 83 | apPwdChars[i], i + EXTRA_HEAD_LEN + ipLen); 84 | totalXor ^= apPwdChars[i]; 85 | } 86 | 87 | byte[] apSsidBytes = ByteUtil.getBytesByString(apSsid); 88 | char[] apSsidChars = new char[apSsidBytes.length]; 89 | 90 | // totalXor will xor apSsidChars no matter whether the ssid is hidden 91 | for (int i = 0; i < apSsidBytes.length; i++) { 92 | apSsidChars[i] = ByteUtil.convertByte2Uint8(apSsidBytes[i]); 93 | totalXor ^= apSsidChars[i]; 94 | } 95 | 96 | if (isSsidHiden) { 97 | for (int i = 0; i < apSsidChars.length; i++) { 98 | mDataCodes[i + EXTRA_HEAD_LEN + ipLen + apPwdLen] = new DataCode( 99 | apSsidChars[i], i + EXTRA_HEAD_LEN + ipLen + apPwdLen); 100 | } 101 | } 102 | 103 | // set total xor last 104 | mDataCodes[4] = new DataCode(totalXor, 4); 105 | } 106 | 107 | @Override 108 | public byte[] getBytes() { 109 | byte[] datumCode = new byte[mDataCodes.length * DataCode.DATA_CODE_LEN]; 110 | for (int i = 0; i < mDataCodes.length; i++) { 111 | System.arraycopy(mDataCodes[i].getBytes(), 0, datumCode, i 112 | * DataCode.DATA_CODE_LEN, DataCode.DATA_CODE_LEN); 113 | } 114 | return datumCode; 115 | } 116 | 117 | @Override 118 | public String toString() { 119 | StringBuilder sb = new StringBuilder(); 120 | byte[] dataBytes = getBytes(); 121 | for (int i = 0; i < dataBytes.length; i++) { 122 | String hexString = ByteUtil.convertByte2HexString(dataBytes[i]); 123 | sb.append("0x"); 124 | if (hexString.length() == 1) { 125 | sb.append("0"); 126 | } 127 | sb.append(hexString).append(" "); 128 | } 129 | return sb.toString(); 130 | } 131 | 132 | @Override 133 | public char[] getU8s() { 134 | byte[] dataBytes = getBytes(); 135 | int len = dataBytes.length / 2; 136 | char[] dataU8s = new char[len]; 137 | byte high, low; 138 | for (int i = 0; i < len; i++) { 139 | high = dataBytes[i * 2]; 140 | low = dataBytes[i * 2 + 1]; 141 | dataU8s[i] = (char) (ByteUtil.combine2bytesToU16(high, low) + EXTRA_LEN); 142 | } 143 | return dataU8s; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /res/layout/main_smartlink.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 35 | 36 | 37 | 38 | 39 | 43 | 44 | 45 | 46 | 47 | 48 | 54 | 55 | 72 | 73 | 74 | 75 | 80 | 86 | 87 | 88 | 89 | 90 | 95 | 96 | 102 | 103 | 104 | 105 | 106 | 110 | 111 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/DataStore/DatabaseHandler_Name.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.DataStore; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import android.content.ContentValues; 7 | import android.content.Context; 8 | import android.database.Cursor; 9 | import android.database.sqlite.SQLiteConstraintException; 10 | import android.database.sqlite.SQLiteDatabase; 11 | import android.database.sqlite.SQLiteOpenHelper; 12 | import android.util.Log; 13 | 14 | public class DatabaseHandler_Name extends SQLiteOpenHelper { 15 | 16 | static final String TAG = "DatabaseHandler_Name"; 17 | 18 | // All Static variables 19 | // Database Version 20 | private static final int DATABASE_VERSION = 1; 21 | 22 | // Database Name 23 | private static final String DATABASE_NAME = "db_Name"; 24 | 25 | // DataStores table name 26 | private static final String TABLE_DataStoreS = "tbl_Name"; 27 | 28 | // DataStores Table Columns names 29 | private static final String KEY_ID = "id"; 30 | private static final String KEY_NAME = "name"; 31 | 32 | public DatabaseHandler_Name(Context context) { 33 | super(context, DATABASE_NAME, null, DATABASE_VERSION); 34 | } 35 | 36 | // Creating Tables 37 | @Override 38 | public void onCreate(SQLiteDatabase db) { 39 | Log.d(TAG, "Database onCreate"); 40 | 41 | String CREATE_DataStoreS_TABLE = "CREATE TABLE " + TABLE_DataStoreS + "(" 42 | + KEY_ID + " INTEGER PRIMARY KEY," 43 | + KEY_NAME + " TEXT" 44 | + ")"; 45 | db.execSQL(CREATE_DataStoreS_TABLE); 46 | } 47 | 48 | // Upgrading database 49 | @Override 50 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 51 | // Drop older table if existed 52 | db.execSQL("DROP TABLE IF EXISTS " + TABLE_DataStoreS); 53 | 54 | // Create tables again 55 | onCreate(db); 56 | } 57 | 58 | /** 59 | * All CRUD(Create, Read, Update, Delete) Operations 60 | */ 61 | 62 | public void dropTable() { 63 | SQLiteDatabase db = this.getWritableDatabase(); 64 | String sql = "drop table " + TABLE_DataStoreS; 65 | db.execSQL(sql); 66 | } 67 | 68 | // Adding new Data 69 | public void addDataStore(DataStore_Name Data) { 70 | SQLiteDatabase db = this.getWritableDatabase(); 71 | 72 | ContentValues values = new ContentValues(); 73 | values.put(KEY_ID, Data.getID()); // Data ID 74 | values.put(KEY_NAME, Data.getName()); // Data Name 75 | 76 | // Inserting Row 77 | try { 78 | db.insertOrThrow(TABLE_DataStoreS, null, values); 79 | } catch (Exception e) { 80 | Log.e(TAG, "Database insert error try update.."); 81 | db.update(TABLE_DataStoreS, values, KEY_ID + " = ?", new String[]{String.valueOf(Data.getID())}); 82 | Log.d(TAG, "Success"); 83 | } 84 | 85 | db.close(); // Closing database connection 86 | } 87 | 88 | // Getting single DataStore_Name 89 | public DataStore_Name getData(int id) { 90 | SQLiteDatabase db = this.getReadableDatabase(); 91 | 92 | Cursor cursor; 93 | cursor = db.query(TABLE_DataStoreS, new String[]{KEY_ID, KEY_NAME}, KEY_ID + "=?", new String[]{String.valueOf(id)}, null, null, null, null); 94 | if (cursor != null) 95 | cursor.moveToFirst(); 96 | 97 | DataStore_Name datastore = new DataStore_Name(cursor.getInt(0), cursor.getString(1)); 98 | // return DataStore_Name 99 | return datastore; 100 | } 101 | 102 | // Getting All DataStores 103 | public List getAllDataStores() { 104 | List dataStoreDataList = new ArrayList(); 105 | // Select All Query 106 | String selectQuery = "SELECT * FROM " + TABLE_DataStoreS; 107 | 108 | SQLiteDatabase db = this.getWritableDatabase(); 109 | Cursor cursor = db.rawQuery(selectQuery, null); 110 | 111 | // looping through all rows and adding to list 112 | if (cursor.moveToFirst()) { 113 | do { 114 | DataStore_Name Data = new DataStore_Name(); 115 | Data.setID(cursor.getInt(0)); 116 | Data.setName(cursor.getString(1)); 117 | // Adding Data to list 118 | dataStoreDataList.add(Data); 119 | } while (cursor.moveToNext()); 120 | } 121 | 122 | // return DataStore_Name list 123 | return dataStoreDataList; 124 | } 125 | 126 | // Updating single Data 127 | public int updateDataStore(DataStore_Name Data) { 128 | SQLiteDatabase db = this.getWritableDatabase(); 129 | 130 | ContentValues values = new ContentValues(); 131 | values.put(KEY_ID, Data.getID()); // Data ID 132 | values.put(KEY_NAME, Data.getName()); // Data Name 133 | 134 | // updating row 135 | return db.update(TABLE_DataStoreS, values, KEY_ID + " = ?", 136 | new String[]{String.valueOf(Data.getID())}); 137 | } 138 | 139 | // Deleting single Data 140 | public void deleteDataStore(DataStore_Name Data) { 141 | SQLiteDatabase db = this.getWritableDatabase(); 142 | db.delete(TABLE_DataStoreS, KEY_ID + " = ?", 143 | new String[]{String.valueOf(Data.getID())}); 144 | db.close(); 145 | } 146 | 147 | 148 | // Getting DataStores Count 149 | public int getDataStoresCount() { 150 | String countQuery = "SELECT * FROM " + TABLE_DataStoreS; 151 | SQLiteDatabase db = this.getReadableDatabase(); 152 | Cursor cursor = db.rawQuery(countQuery, null); 153 | cursor.close(); 154 | 155 | // return count 156 | return cursor.getCount(); 157 | } 158 | 159 | public boolean IsDataInDB(int id) { 160 | SQLiteDatabase db = this.getReadableDatabase(); 161 | Cursor cursor; 162 | cursor = db.query(TABLE_DataStoreS, new String[]{KEY_ID, KEY_NAME}, KEY_ID + "=?", new String[]{String.valueOf(id)}, null, null, null, null); 163 | 164 | if(cursor.getCount() <= 0){ 165 | cursor.close(); 166 | return false; 167 | } 168 | cursor.close(); 169 | return true; 170 | } 171 | 172 | 173 | } 174 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/GlobalClass.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gerry on 19.07.15. 3 | */ 4 | package com.espressif.esp8266_iot; 5 | 6 | import android.app.Application; 7 | import android.content.Context; 8 | import android.net.wifi.WifiManager; 9 | 10 | public class GlobalClass extends Application { 11 | 12 | private String apSsid = ""; 13 | private String apPassword = ""; 14 | private String apBssid = ""; 15 | private Boolean isSsidHidden = false; 16 | private String isSsidHiddenStr = "NO"; 17 | private String taskResultCountStr = "1"; 18 | private Integer taskResultCount = 0; 19 | private String mqttIpStr = "192.168.178.5"; 20 | private String mqttPortStr = "1883"; 21 | private String mqttUserStr = ""; 22 | private String mqttPassStr = ""; 23 | private Boolean mqttSSLBool = false; 24 | 25 | private int mTargetPort = 18666; 26 | private int mRemotePort = 18566; 27 | 28 | private String upgradeIpStr = "84.200.150.145"; 29 | private String upgradePortStr = "88"; 30 | 31 | private String ImpulsLengthStr = "1000"; 32 | 33 | /** 34 | * ******************************************************************************* 35 | */ 36 | public String get_apSsid() { return apSsid; } 37 | public void set_apSsid(String Value) { apSsid = Value; } 38 | 39 | /** 40 | * ******************************************************************************* 41 | */ 42 | public String get_apPassword() { 43 | return apPassword; 44 | } 45 | public void set_apPassword(String Value) { 46 | apPassword = Value; 47 | } 48 | 49 | /** 50 | * ******************************************************************************* 51 | */ 52 | public String get_apBssid() { 53 | return apBssid; 54 | } 55 | public void set_apBssid(String Value) { 56 | apBssid = Value; 57 | } 58 | 59 | /** 60 | * ******************************************************************************* 61 | */ 62 | public Boolean get_isSsidHidden() { 63 | return isSsidHidden; 64 | } 65 | public void set_isSsidHidden(Boolean Value) { 66 | isSsidHidden = Value; 67 | } 68 | 69 | /** 70 | * ******************************************************************************* 71 | */ 72 | public String get_isSsidHiddenStr() { 73 | return isSsidHiddenStr; 74 | } 75 | public void set_isSsidHiddenStr(String Value) { 76 | isSsidHiddenStr = Value; 77 | } 78 | 79 | /** 80 | * ******************************************************************************* 81 | */ 82 | public Integer get_taskResultCount() { 83 | return taskResultCount; 84 | } 85 | public void set_taskResultCount(Integer Value) { 86 | taskResultCount = Value; 87 | } 88 | /** 89 | * ******************************************************************************* 90 | */ 91 | public String get_taskResultCountStr() { 92 | return taskResultCountStr; 93 | } 94 | public void set_taskResultCountStr(String Value) { 95 | taskResultCountStr = Value; 96 | } 97 | 98 | /** 99 | * ******************************************************************************* 100 | */ 101 | public String get_mqttIp() { 102 | return mqttIpStr; 103 | } 104 | public void set_mqttIp(String Value) { 105 | mqttIpStr = Value; 106 | } 107 | 108 | /** 109 | * ******************************************************************************* 110 | */ 111 | public String get_mqttPort() { 112 | return mqttPortStr; 113 | } 114 | public void set_mqttPort(String Value) { 115 | mqttPortStr = Value; 116 | } 117 | 118 | /** 119 | * ******************************************************************************* 120 | */ 121 | public String get_mqttUser() { 122 | return mqttUserStr; 123 | } 124 | public void set_mqttUser(String Value) { 125 | mqttUserStr = Value; 126 | } 127 | 128 | /** 129 | * ******************************************************************************* 130 | */ 131 | public String get_mqttPass() { return mqttPassStr; } 132 | public void set_mqttPass(String Value) { mqttPassStr = Value; } 133 | /** 134 | * ******************************************************************************* 135 | */ 136 | public Boolean get_mqttSSL() { return mqttSSLBool; } 137 | public void set_mqttSSL(Boolean Value) { mqttSSLBool = Value;} 138 | 139 | /** 140 | * ******************************************************************************* 141 | */ 142 | public int get_TargetPort() { return mTargetPort; } 143 | 144 | /** 145 | * ******************************************************************************* 146 | */ 147 | public int get_RemotePort() { return mRemotePort; } 148 | 149 | /** 150 | * ******************************************************************************* 151 | */ 152 | public String get_upgradeIp() { 153 | return upgradeIpStr; 154 | } 155 | public void set_upgradeIp(String Value) { 156 | upgradeIpStr = Value; 157 | } 158 | 159 | /** 160 | * ******************************************************************************* 161 | */ 162 | public String get_upgradePort() { 163 | return upgradePortStr; 164 | } 165 | public void set_upgradePort(String Value) { 166 | upgradePortStr = Value; 167 | } 168 | 169 | /** 170 | * ******************************************************************************* 171 | */ 172 | public String get_ImpulsLengthStr() { 173 | return ImpulsLengthStr; 174 | } 175 | public void set_ImpulsLengthStr(String Value) { 176 | ImpulsLengthStr = Value; 177 | } 178 | 179 | /** 180 | * ******************************************************************************* 181 | */ 182 | public String get_LocalBroadcastAddress(Context context) { 183 | WifiManager wifi; 184 | wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); 185 | int ipAddress = wifi.getConnectionInfo().getIpAddress(); 186 | String ipAddress_str = String.format("%d.%d.%d.%d", 187 | (ipAddress & 0xff), 188 | (ipAddress >> 8 & 0xff), 189 | (ipAddress >> 16 & 0xff), 190 | (255)); 191 | return ipAddress_str; 192 | } 193 | /***********************************************************************************/ 194 | 195 | } -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/DataStore/DatabaseHandler_Data.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gerry on 22.07.2015. 3 | * http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/ 4 | */ 5 | package com.espressif.esp8266_iot.DataStore; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | import android.content.ContentValues; 11 | import android.content.Context; 12 | import android.database.Cursor; 13 | import android.database.sqlite.SQLiteConstraintException; 14 | import android.database.sqlite.SQLiteDatabase; 15 | import android.database.sqlite.SQLiteOpenHelper; 16 | import android.util.Log; 17 | 18 | public class DatabaseHandler_Data extends SQLiteOpenHelper { 19 | 20 | static final String TAG = "DatabaseHandler_Data"; 21 | 22 | // All Static variables 23 | // Database Version 24 | private static final int DATABASE_VERSION = 1; 25 | 26 | // Database Name 27 | private static final String DATABASE_NAME = "db_Data"; 28 | 29 | // DataStores table name 30 | private static final String TABLE_DataStoreS = "tbl_Data"; 31 | 32 | // DataStores Table Columns names 33 | private static final String KEY_ID = "id"; 34 | private static final String KEY_DEVID = "devid"; 35 | private static final String KEY_ADDRESS = "address"; 36 | private static final String KEY_FUNC = "function"; 37 | private static final String KEY_STATUS = "status"; 38 | private static final String KEY_ACTIV = "activ"; 39 | 40 | public DatabaseHandler_Data(Context context) { 41 | super(context, DATABASE_NAME, null, DATABASE_VERSION); 42 | } 43 | 44 | // Creating Tables 45 | @Override 46 | public void onCreate(SQLiteDatabase db) { 47 | Log.d(TAG, "Database onCreate"); 48 | 49 | String CREATE_DataStoreS_TABLE = "CREATE TABLE " + TABLE_DataStoreS + "(" 50 | + KEY_ID + " INTEGER PRIMARY KEY," 51 | + KEY_DEVID + " TEXT," 52 | + KEY_ADDRESS + " TEXT," 53 | + KEY_FUNC + " TEXT," 54 | + KEY_STATUS + " TEXT," 55 | + KEY_ACTIV + " INTEGER" 56 | + ")"; 57 | db.execSQL(CREATE_DataStoreS_TABLE); 58 | } 59 | 60 | // Upgrading database 61 | @Override 62 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 63 | // Drop older table if existed 64 | db.execSQL("DROP TABLE IF EXISTS " + TABLE_DataStoreS); 65 | 66 | // Create tables again 67 | onCreate(db); 68 | } 69 | 70 | /** 71 | * All CRUD(Create, Read, Update, Delete) Operations 72 | */ 73 | 74 | public void dropTable() { 75 | SQLiteDatabase db = this.getWritableDatabase(); 76 | String sql = "drop table " + TABLE_DataStoreS; 77 | db.execSQL(sql); 78 | } 79 | 80 | // Adding new Data 81 | public void addDataStore(DataStore_Data Data) { 82 | SQLiteDatabase db = this.getWritableDatabase(); 83 | 84 | ContentValues values = new ContentValues(); 85 | values.put(KEY_ID, Data.getID()); // Data ID 86 | values.put(KEY_DEVID, Data.getDevID()); // Device ID 87 | values.put(KEY_ADDRESS, Data.getAddress()); // Data Address 88 | values.put(KEY_FUNC, Data.getFunction()); // Data Function 89 | values.put(KEY_STATUS, Data.getStatus()); // Data Status 90 | values.put(KEY_ACTIV, Data.getisActive()); // Data Active 91 | 92 | // Inserting Row 93 | db.insert(TABLE_DataStoreS, null, values); 94 | try { 95 | db.insertOrThrow(TABLE_DataStoreS, null, values); 96 | } catch (SQLiteConstraintException e) { 97 | Log.e(TAG, "Database insert error try update.."); 98 | db.update(TABLE_DataStoreS, values, KEY_ID + " = ?", new String[]{String.valueOf(Data.getID())}); 99 | Log.d(TAG, "Success"); 100 | } 101 | db.close(); // Closing database connection 102 | } 103 | 104 | // Getting single DataStore_Data 105 | public DataStore_Data getData(int id) { 106 | SQLiteDatabase db = this.getReadableDatabase(); 107 | 108 | Cursor cursor; 109 | cursor = db.query(TABLE_DataStoreS, new String[]{KEY_ID, KEY_DEVID, KEY_ADDRESS, KEY_FUNC, KEY_STATUS, KEY_ACTIV}, KEY_ID + "=?", new String[]{String.valueOf(id)}, null, null, null, null); 110 | if (cursor != null) 111 | cursor.moveToFirst(); 112 | 113 | DataStore_Data datastore = new DataStore_Data( cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getInt(5) ); 114 | // return DataStore_Data 115 | return datastore; 116 | } 117 | 118 | // Getting All DataStores 119 | public List getAllDataStores() { 120 | List dataStoreDataList = new ArrayList(); 121 | // Select All Query 122 | String selectQuery = "SELECT * FROM " + TABLE_DataStoreS; 123 | 124 | SQLiteDatabase db = this.getWritableDatabase(); 125 | Cursor cursor = db.rawQuery(selectQuery, null); 126 | 127 | // looping through all rows and adding to list 128 | if (cursor.moveToFirst()) { 129 | do { 130 | DataStore_Data DataStore_Data = new DataStore_Data(); 131 | DataStore_Data.setID(cursor.getInt(0)); 132 | DataStore_Data.setAddress(cursor.getString(1)); 133 | DataStore_Data.setAddress(cursor.getString(2)); 134 | DataStore_Data.setFunktion(cursor.getString(3)); 135 | DataStore_Data.setStatus(cursor.getString(4)); 136 | DataStore_Data.setisActive(cursor.getInt(5)); 137 | // Adding DataStore_Data to list 138 | dataStoreDataList.add(DataStore_Data); 139 | } while (cursor.moveToNext()); 140 | } 141 | 142 | // return DataStore_Data list 143 | return dataStoreDataList; 144 | } 145 | 146 | // Updating single Data 147 | public int updateDataStore(DataStore_Data Data) { 148 | SQLiteDatabase db = this.getWritableDatabase(); 149 | 150 | ContentValues values = new ContentValues(); 151 | values.put(KEY_ID, Data.getID()); // Data ID 152 | values.put(KEY_DEVID, Data.getDevID()); // Data ID 153 | values.put(KEY_ADDRESS, Data.getAddress()); // Data Name 154 | values.put(KEY_FUNC, Data.getFunction()); // Data Function 155 | values.put(KEY_STATUS, Data.getStatus()); // Data Active 156 | values.put(KEY_ACTIV, Data.getisActive()); // Data Active 157 | 158 | // updating row 159 | return db.update(TABLE_DataStoreS, values, KEY_ID + " = ?", 160 | new String[]{String.valueOf(Data.getID())}); 161 | } 162 | 163 | // Deleting single DataStore_Data 164 | public void deleteDataStore(DataStore_Data Data) { 165 | SQLiteDatabase db = this.getWritableDatabase(); 166 | db.delete(TABLE_DataStoreS, KEY_ID + " = ?", new String[]{String.valueOf(Data.getID())}); 167 | db.close(); 168 | } 169 | 170 | 171 | // Getting DataStores Count 172 | public int getDataStoresCount() { 173 | String countQuery = "SELECT * FROM " + TABLE_DataStoreS; 174 | SQLiteDatabase db = this.getReadableDatabase(); 175 | Cursor cursor = db.rawQuery(countQuery, null); 176 | cursor.close(); 177 | 178 | // return count 179 | return cursor.getCount(); 180 | } 181 | 182 | public boolean IsDataInDB(int id) { 183 | SQLiteDatabase db = this.getReadableDatabase(); 184 | Cursor cursor; 185 | cursor = db.query(TABLE_DataStoreS, new String[]{KEY_ID}, KEY_ID + "=?", new String[]{String.valueOf(id)}, null, null, null, null); 186 | 187 | if(cursor.getCount() <= 0){ 188 | cursor.close(); 189 | return false; 190 | } 191 | cursor.close(); 192 | return true; 193 | } 194 | 195 | } -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/util/ByteUtil.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.util; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.util.Random; 5 | 6 | /** 7 | * In Java, it don't support unsigned int, so we use char to replace uint8. 8 | * The range of byte is [-128,127], and the range of char is [0,65535]. 9 | * So the byte could used to store the uint8. 10 | * (We assume that the String could be mapped to assic) 11 | * @author afunx 12 | * 13 | */ 14 | public class ByteUtil { 15 | 16 | public static final String ESPTOUCH_ENCODING_CHARSET = "UTF-8"; 17 | 18 | /** 19 | * Put String to byte[] 20 | * 21 | * @param destbytes 22 | * the byte[] of dest 23 | * @param srcString 24 | * the String of src 25 | * @param destOffset 26 | * the offset of byte[] 27 | * @param srcOffset 28 | * the offset of String 29 | * @param count 30 | * the count of dest, and the count of src as well 31 | */ 32 | public static void putString2bytes(byte[] destbytes, String srcString, 33 | int destOffset, int srcOffset, int count) { 34 | for (int i = 0; i < count; i++) { 35 | destbytes[count + i] = srcString.getBytes()[i]; 36 | } 37 | } 38 | 39 | /** 40 | * Convert uint8 into char( we treat char as uint8) 41 | * 42 | * @param uint8 43 | * the unit8 to be converted 44 | * @return the byte of the unint8 45 | */ 46 | public static byte convertUint8toByte(char uint8) { 47 | if (uint8 > Byte.MAX_VALUE - Byte.MIN_VALUE) { 48 | throw new RuntimeException("Out of Boundary"); 49 | } 50 | return (byte) uint8; 51 | } 52 | 53 | /** 54 | * Convert char into uint8( we treat char as uint8 ) 55 | * 56 | * @param b 57 | * the byte to be converted 58 | * @return the char(uint8) 59 | */ 60 | public static char convertByte2Uint8(byte b) { 61 | // char will be promoted to int for char don't support & operator 62 | // & 0xff could make negatvie value to positive 63 | return (char) (b & 0xff); 64 | } 65 | 66 | /** 67 | * Convert byte[] into char[]( we treat char[] as uint8[]) 68 | * 69 | * @param bytes 70 | * the byte[] to be converted 71 | * @return the char[](uint8[]) 72 | */ 73 | public static char[] convertBytes2Uint8s(byte[] bytes) { 74 | int len = bytes.length; 75 | char[] uint8s = new char[len]; 76 | for (int i = 0; i < len; i++) { 77 | uint8s[i] = convertByte2Uint8(bytes[i]); 78 | } 79 | return uint8s; 80 | } 81 | 82 | /** 83 | * Put byte[] into char[]( we treat char[] as uint8[]) 84 | * 85 | * @param destUint8s 86 | * the char[](uint8[]) array 87 | * @param srcBytes 88 | * the byte[] 89 | * @param destOffset 90 | * the offset of char[](uint8[]) 91 | * @param srcOffset 92 | * the offset of byte[] 93 | * @param count 94 | * the count of dest, and the count of src as well 95 | */ 96 | public static void putbytes2Uint8s(char[] destUint8s, byte[] srcBytes, 97 | int destOffset, int srcOffset, int count) { 98 | for (int i = 0; i < count; i++) { 99 | destUint8s[destOffset + i] = convertByte2Uint8(srcBytes[srcOffset 100 | + i]); 101 | } 102 | } 103 | 104 | /** 105 | * Convert byte to Hex String 106 | * 107 | * @param b 108 | * the byte to be converted 109 | * @return the Hex String 110 | */ 111 | public static String convertByte2HexString(byte b) { 112 | char u8 = convertByte2Uint8(b); 113 | return Integer.toHexString(u8); 114 | } 115 | 116 | /** 117 | * Convert char(uint8) to Hex String 118 | * 119 | * @param u8 120 | * the char(uint8) to be converted 121 | * @return the Hex String 122 | */ 123 | public static String convertU8ToHexString(char u8) { 124 | return Integer.toHexString(u8); 125 | } 126 | 127 | /** 128 | * Split uint8 to 2 bytes of high byte and low byte. e.g. 20 = 0x14 should 129 | * be split to [0x01,0x04] 0x01 is high byte and 0x04 is low byte 130 | * 131 | * @param uint8 132 | * the char(uint8) 133 | * @return the high and low bytes be split, byte[0] is high and byte[1] is 134 | * low 135 | */ 136 | public static byte[] splitUint8To2bytes(char uint8) { 137 | if (uint8 < 0 || uint8 > 0xff) { 138 | throw new RuntimeException("Out of Boundary"); 139 | } 140 | String hexString = Integer.toHexString(uint8); 141 | byte low; 142 | byte high; 143 | if (hexString.length() > 1) { 144 | high = (byte) Integer.parseInt(hexString.substring(0, 1), 16); 145 | low = (byte) Integer.parseInt(hexString.substring(1, 2), 16); 146 | } else { 147 | high = 0; 148 | low = (byte) Integer.parseInt(hexString.substring(0, 1), 16); 149 | } 150 | byte[] result = new byte[] { high, low }; 151 | return result; 152 | } 153 | 154 | /** 155 | * Combine 2 bytes (high byte and low byte) to one whole byte 156 | * 157 | * @param high 158 | * the high byte 159 | * @param low 160 | * the low byte 161 | * @return the whole byte 162 | */ 163 | public static byte combine2bytesToOne(byte high, byte low) { 164 | if (high < 0 || high > 0xf || low < 0 || low > 0xf) { 165 | throw new RuntimeException("Out of Boundary"); 166 | } 167 | return (byte) (high << 4 | low); 168 | } 169 | 170 | /** 171 | * Combine 2 bytes (high byte and low byte) to 172 | * 173 | * @param high 174 | * the high byte 175 | * @param low 176 | * the low byte 177 | * @return the char(u8) 178 | */ 179 | public static char combine2bytesToU16(byte high, byte low) { 180 | char highU8 = convertByte2Uint8(high); 181 | char lowU8 = convertByte2Uint8(low); 182 | return (char) (highU8 << 8 | lowU8); 183 | } 184 | 185 | /** 186 | * Generate the random byte to be sent 187 | * 188 | * @return the random byte 189 | */ 190 | private static byte randomByte() { 191 | return (byte) (127 - new Random().nextInt(256)); 192 | } 193 | 194 | /** 195 | * Generate the random byte to be sent 196 | * 197 | * @param len 198 | * the len presented by u8 199 | * @return the byte[] to be sent 200 | */ 201 | public static byte[] randomBytes(char len) { 202 | byte[] data = new byte[len]; 203 | for (int i = 0; i < len; i++) { 204 | data[i] = randomByte(); 205 | } 206 | return data; 207 | } 208 | 209 | public static byte[] genSpecBytes(char len) { 210 | byte[] data = new byte[len]; 211 | for (int i = 0; i < len; i++) { 212 | data[i] = '1'; 213 | } 214 | return data; 215 | } 216 | 217 | /** 218 | * Generate the random byte to be sent 219 | * 220 | * @param len 221 | * the len presented by byte 222 | * @return the byte[] to be sent 223 | */ 224 | public static byte[] randomBytes(byte len) { 225 | char u8 = convertByte2Uint8(len); 226 | return randomBytes(u8); 227 | } 228 | 229 | /** 230 | * Generate the specific byte to be sent 231 | * @param len 232 | * the len presented by byte 233 | * @return the byte[] 234 | */ 235 | public static byte[] genSpecBytes(byte len) { 236 | char u8 = convertByte2Uint8(len); 237 | return genSpecBytes(u8); 238 | } 239 | 240 | public static String parseBssid(byte[] bssidBytes, int offset, int count) { 241 | byte[] bytes = new byte[count]; 242 | for (int i = 0; i < count; i++) { 243 | bytes[i] = bssidBytes[i + offset]; 244 | } 245 | return parseBssid(bytes); 246 | } 247 | 248 | /** 249 | * parse "24,-2,52,-102,-93,-60" to "18,fe,34,9a,a3,c4" 250 | * parse the bssid from hex to String 251 | * @param bssidBytes the hex bytes bssid, e.g. {24,-2,52,-102,-93,-60} 252 | * @return the String of bssid, e.g. 18fe349aa3c4 253 | */ 254 | public static String parseBssid(byte[] bssidBytes) 255 | { 256 | StringBuilder sb = new StringBuilder(); 257 | int k; 258 | String hexK; 259 | String str; 260 | for (int i = 0; i < bssidBytes.length; i++) 261 | { 262 | k = 0xff & bssidBytes[i]; 263 | hexK = Integer.toHexString(k); 264 | str = ((k < 16) ? ("0" + hexK) : (hexK)); 265 | System.out.println(str); 266 | sb.append(str); 267 | } 268 | return sb.toString(); 269 | } 270 | 271 | /** 272 | * @param string the string to be used 273 | * @return the byte[] of String according to {@link #ESPTOUCH_ENCODING_CHARSET} 274 | */ 275 | public static byte[] getBytesByString(String string) { 276 | try { 277 | return string.getBytes(ESPTOUCH_ENCODING_CHARSET); 278 | } catch (UnsupportedEncodingException e) { 279 | throw new IllegalArgumentException("the charset is invalid"); 280 | } 281 | } 282 | 283 | private static void test_splitUint8To2bytes() { 284 | // 20 = 0x14 285 | byte[] result = splitUint8To2bytes((char) 20); 286 | if (result[0] == 1 && result[1] == 4) { 287 | System.out.println("test_splitUint8To2bytes(): pass"); 288 | } else { 289 | System.out.println("test_splitUint8To2bytes(): fail"); 290 | } 291 | } 292 | 293 | private static void test_combine2bytesToOne() { 294 | byte high = 0x01; 295 | byte low = 0x04; 296 | if (combine2bytesToOne(high, low) == 20) { 297 | System.out.println("test_combine2bytesToOne(): pass"); 298 | } else { 299 | System.out.println("test_combine2bytesToOne(): fail"); 300 | } 301 | } 302 | 303 | private static void test_convertChar2Uint8() { 304 | byte b1 = 'a'; 305 | // -128: 1000 0000 should be 128 in unsigned char 306 | // -1: 1111 1111 should be 255 in unsigned char 307 | byte b2 = (byte) -128; 308 | byte b3 = (byte) -1; 309 | if (convertByte2Uint8(b1) == 97 && convertByte2Uint8(b2) == 128 310 | && convertByte2Uint8(b3) == 255) { 311 | System.out.println("test_convertChar2Uint8(): pass"); 312 | } else { 313 | System.out.println("test_convertChar2Uint8(): fail"); 314 | } 315 | } 316 | 317 | private static void test_convertUint8toByte() { 318 | char c1 = 'a'; 319 | // 128: 1000 0000 should be -128 in byte 320 | // 255: 1111 1111 should be -1 in byte 321 | char c2 = 128; 322 | char c3 = 255; 323 | if (convertUint8toByte(c1) == 97 && convertUint8toByte(c2) == -128 324 | && convertUint8toByte(c3) == -1) { 325 | System.out.println("test_convertUint8toByte(): pass"); 326 | } else { 327 | System.out.println("test_convertUint8toByte(): fail"); 328 | } 329 | } 330 | 331 | private static void test_parseBssid() { 332 | byte b[] = {15, -2, 52, -102, -93, -60}; 333 | if(parseBssid(b).equals("0ffe349aa3c4")) 334 | { 335 | System.out.println("test_parseBssid(): pass"); 336 | } 337 | else 338 | { 339 | System.out.println("test_parseBssid(): fail"); 340 | } 341 | } 342 | 343 | public static void main(String args[]) { 344 | test_convertUint8toByte(); 345 | test_convertChar2Uint8(); 346 | test_splitUint8To2bytes(); 347 | test_combine2bytesToOne(); 348 | test_parseBssid(); 349 | } 350 | 351 | } 352 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/task/__EsptouchTask.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.task; 2 | 3 | import android.content.Context; 4 | import android.os.Looper; 5 | import android.text.TextUtils; 6 | import android.util.Log; 7 | 8 | import com.espressif.esp8266_iot.EsptouchResult; 9 | import com.espressif.esp8266_iot.IEsptouchResult; 10 | import com.espressif.esp8266_iot.protocol.EsptouchGenerator; 11 | import com.espressif.esp8266_iot.udp.UDPSocketClient; 12 | import com.espressif.esp8266_iot.udp.UDPSocketServer; 13 | import com.espressif.esp8266_iot.util.ByteUtil; 14 | import com.espressif.esp8266_iot.util.EspNetUtil; 15 | 16 | import java.net.InetAddress; 17 | import java.util.ArrayList; 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.concurrent.atomic.AtomicBoolean; 22 | 23 | public class __EsptouchTask implements __IEsptouchTask { 24 | 25 | /** 26 | * one indivisible data contain 3 9bits info 27 | */ 28 | private static final int ONE_DATA_LEN = 3; 29 | 30 | private static final String TAG = "__EsptouchTask"; 31 | 32 | private volatile List mEsptouchResultList; 33 | private volatile boolean mIsSuc = false; 34 | private volatile boolean mIsInterrupt = false; 35 | private volatile boolean mIsExecuted = false; 36 | private final UDPSocketClient mSocketClient; 37 | private final UDPSocketServer mSocketServer; 38 | private final String mApSsid; 39 | private final String mApBssid; 40 | private final boolean mIsSsidHidden; 41 | private final String mApPassword; 42 | private final Context mContext; 43 | private AtomicBoolean mIsCancelled; 44 | private IEsptouchTaskParameter mParameter; 45 | private volatile Map mBssidTaskSucCountMap; 46 | 47 | public __EsptouchTask(String apSsid, String apBssid, String apPassword, Context context, IEsptouchTaskParameter parameter 48 | ,boolean isSsidHidden) { 49 | if (TextUtils.isEmpty(apSsid)) { 50 | throw new IllegalArgumentException( 51 | "the apSsid should be null or empty"); 52 | } 53 | if (apPassword == null) { 54 | apPassword = ""; 55 | } 56 | mContext = context; 57 | mApSsid = apSsid; 58 | mApBssid = apBssid; 59 | mApPassword = apPassword; 60 | mIsCancelled = new AtomicBoolean(false); 61 | mSocketClient = new UDPSocketClient(); 62 | mParameter = parameter; 63 | mSocketServer = new UDPSocketServer(mParameter.getPortListening(), 64 | mParameter.getWaitUdpTotalMillisecond(), 65 | context); 66 | mIsSsidHidden = isSsidHidden; 67 | mEsptouchResultList = new ArrayList(); 68 | mBssidTaskSucCountMap = new HashMap(); 69 | } 70 | 71 | private void __putEsptouchResult(boolean isSuc, String bssid, 72 | InetAddress inetAddress) { 73 | synchronized (mEsptouchResultList) { 74 | // check whether the result receive enough UDP response 75 | boolean isTaskSucCountEnough = false; 76 | Integer count = mBssidTaskSucCountMap.get(bssid); 77 | if (count == null) { 78 | count = 0; 79 | } 80 | ++count; 81 | if (__IEsptouchTask.DEBUG) { 82 | Log.d(TAG, "__putEsptouchResult(): count = " + count); 83 | } 84 | mBssidTaskSucCountMap.put(bssid, count); 85 | isTaskSucCountEnough = count >= mParameter 86 | .getThresholdSucBroadcastCount(); 87 | if (!isTaskSucCountEnough) { 88 | if (__IEsptouchTask.DEBUG) { 89 | Log.d(TAG, "__putEsptouchResult(): count = " + count 90 | + ", isn't enough"); 91 | } 92 | return; 93 | } 94 | // check whether the result is in the mEsptouchResultList already 95 | boolean isExist = false; 96 | for (IEsptouchResult esptouchResultInList : mEsptouchResultList) { 97 | if (esptouchResultInList.getBssid().equals(bssid)) { 98 | isExist = true; 99 | break; 100 | } 101 | } 102 | // only add the result who isn't in the mEsptouchResultList 103 | if (!isExist) { 104 | if (__IEsptouchTask.DEBUG) { 105 | Log.d(TAG, "__putEsptouchResult(): put one more result"); 106 | } 107 | IEsptouchResult esptouchResult = new EsptouchResult(isSuc, 108 | bssid, inetAddress); 109 | mEsptouchResultList.add(esptouchResult); 110 | } 111 | } 112 | } 113 | 114 | private List __getEsptouchResultList() { 115 | synchronized (mEsptouchResultList) { 116 | if (mEsptouchResultList.isEmpty()) { 117 | EsptouchResult esptouchResultFail = new EsptouchResult(false, 118 | null, null); 119 | esptouchResultFail.setIsCancelled(mIsCancelled.get()); 120 | mEsptouchResultList.add(esptouchResultFail); 121 | } 122 | return mEsptouchResultList; 123 | } 124 | } 125 | 126 | private synchronized void __interrupt() { 127 | if (!mIsInterrupt) { 128 | mIsInterrupt = true; 129 | mSocketClient.interrupt(); 130 | mSocketServer.interrupt(); 131 | // interrupt the current Thread which is used to wait for udp response 132 | Thread.currentThread().interrupt(); 133 | } 134 | } 135 | 136 | @Override 137 | public void interrupt() { 138 | if (__IEsptouchTask.DEBUG) { 139 | Log.d(TAG, "interrupt()"); 140 | } 141 | mIsCancelled.set(true); 142 | __interrupt(); 143 | } 144 | 145 | private void __listenAsyn(final int expectDataLen) { 146 | new Thread() { 147 | public void run() { 148 | if (__IEsptouchTask.DEBUG) { 149 | Log.d(TAG, "__listenAsyn() start"); 150 | } 151 | long startTimestamp = System.currentTimeMillis(); 152 | byte[] apSsidAndPassword = ByteUtil.getBytesByString(mApSsid 153 | + mApPassword); 154 | byte expectOneByte = (byte) (apSsidAndPassword.length + 9); 155 | if (__IEsptouchTask.DEBUG) { 156 | Log.i(TAG, "expectOneByte: " + (0 + expectOneByte)); 157 | } 158 | byte receiveOneByte = -1; 159 | byte[] receiveBytes = null; 160 | while (mEsptouchResultList.size() < mParameter 161 | .getExpectTaskResultCount() && !mIsInterrupt) { 162 | receiveBytes = mSocketServer 163 | .receiveSpecLenBytes(expectDataLen); 164 | if (receiveBytes != null) { 165 | receiveOneByte = receiveBytes[0]; 166 | } else { 167 | receiveOneByte = -1; 168 | } 169 | if (receiveOneByte == expectOneByte) { 170 | if (__IEsptouchTask.DEBUG) { 171 | Log.i(TAG, "receive correct broadcast"); 172 | } 173 | // change the socket's timeout 174 | long consume = System.currentTimeMillis() 175 | - startTimestamp; 176 | int timeout = (int) (mParameter 177 | .getWaitUdpTotalMillisecond() - consume); 178 | if (timeout < 0) { 179 | if (__IEsptouchTask.DEBUG) { 180 | Log.i(TAG, "esp8266_iot timeout"); 181 | } 182 | break; 183 | } else { 184 | if (__IEsptouchTask.DEBUG) { 185 | Log.i(TAG, "mSocketServer's new timeout is " 186 | + timeout + " milliseconds"); 187 | } 188 | mSocketServer.setSoTimeout(timeout); 189 | if (__IEsptouchTask.DEBUG) { 190 | Log.i(TAG, "receive correct broadcast"); 191 | } 192 | if (receiveBytes != null) { 193 | String bssid = ByteUtil.parseBssid( 194 | receiveBytes, 195 | mParameter.getEsptouchResultOneLen(), 196 | mParameter.getEsptouchResultMacLen()); 197 | InetAddress inetAddress = EspNetUtil 198 | .parseInetAddr( 199 | receiveBytes, 200 | mParameter.getEsptouchResultOneLen() 201 | + mParameter.getEsptouchResultMacLen(), 202 | mParameter.getEsptouchResultIpLen()); 203 | __putEsptouchResult(true, bssid, inetAddress); 204 | } 205 | } 206 | } else { 207 | if (__IEsptouchTask.DEBUG) { 208 | Log.i(TAG, "receive rubbish message, just ignore"); 209 | } 210 | } 211 | } 212 | mIsSuc = mEsptouchResultList.size() >= mParameter 213 | .getExpectTaskResultCount(); 214 | __EsptouchTask.this.__interrupt(); 215 | if (__IEsptouchTask.DEBUG) { 216 | Log.d(TAG, "__listenAsyn() finish"); 217 | } 218 | } 219 | }.start(); 220 | } 221 | 222 | private boolean __execute(IEsptouchGenerator generator) { 223 | 224 | long startTime = System.currentTimeMillis(); 225 | long currentTime = startTime; 226 | long lastTime = currentTime - mParameter.getTimeoutTotalCodeMillisecond(); 227 | 228 | byte[][] gcBytes2 = generator.getGCBytes2(); 229 | byte[][] dcBytes2 = generator.getDCBytes2(); 230 | 231 | int index = 0; 232 | while (!mIsInterrupt) { 233 | if (currentTime - lastTime >= mParameter.getTimeoutTotalCodeMillisecond()) { 234 | if (__IEsptouchTask.DEBUG) { 235 | Log.d(TAG, "send gc code "); 236 | } 237 | // send guide code 238 | while (!mIsInterrupt 239 | && System.currentTimeMillis() - currentTime < mParameter 240 | .getTimeoutGuideCodeMillisecond()) { 241 | mSocketClient.sendData(gcBytes2, 242 | mParameter.getTargetHostname(), 243 | mParameter.getTargetPort(), 244 | mParameter.getIntervalGuideCodeMillisecond()); 245 | // check whether the udp is send enough time 246 | if (System.currentTimeMillis() - startTime > mParameter.getWaitUdpSendingMillisecond()) { 247 | break; 248 | } 249 | } 250 | lastTime = currentTime; 251 | } else { 252 | mSocketClient.sendData(dcBytes2, index, ONE_DATA_LEN, 253 | mParameter.getTargetHostname(), 254 | mParameter.getTargetPort(), 255 | mParameter.getIntervalDataCodeMillisecond()); 256 | index = (index + ONE_DATA_LEN) % dcBytes2.length; 257 | } 258 | currentTime = System.currentTimeMillis(); 259 | // check whether the udp is send enough time 260 | if (currentTime - startTime > mParameter.getWaitUdpSendingMillisecond()) { 261 | break; 262 | } 263 | } 264 | 265 | return mIsSuc; 266 | } 267 | 268 | private void __checkTaskValid() { 269 | // !!!NOTE: the esp8266_iot task could be executed only once 270 | if (this.mIsExecuted) { 271 | throw new IllegalStateException( 272 | "the Esptouch task could be executed only once"); 273 | } 274 | this.mIsExecuted = true; 275 | } 276 | 277 | @Override 278 | public IEsptouchResult executeForResult() throws RuntimeException { 279 | return executeForResults(1).get(0); 280 | } 281 | 282 | @Override 283 | public boolean isCancelled() { 284 | return this.mIsCancelled.get(); 285 | } 286 | 287 | @Override 288 | public List executeForResults(int expectTaskResultCount) 289 | throws RuntimeException { 290 | __checkTaskValid(); 291 | 292 | mParameter.setExpectTaskResultCount(expectTaskResultCount); 293 | 294 | if (__IEsptouchTask.DEBUG) { 295 | Log.d(TAG, "execute()"); 296 | } 297 | if (Looper.myLooper() == Looper.getMainLooper()) { 298 | throw new RuntimeException( 299 | "Don't call the esp8266_iot Task at EsptouchDemoActivity(UI) thread directly."); 300 | } 301 | InetAddress localInetAddress = EspNetUtil.getLocalInetAddress(mContext); 302 | if (__IEsptouchTask.DEBUG) { 303 | Log.i(TAG, "localInetAddress: " + localInetAddress); 304 | } 305 | // generator the esp8266_iot byte[][] to be transformed, which will cost 306 | // some time(maybe a bit much) 307 | IEsptouchGenerator generator = new EsptouchGenerator(mApSsid, mApBssid, 308 | mApPassword, localInetAddress, mIsSsidHidden); 309 | // listen the esp8266_iot result asyn 310 | __listenAsyn(mParameter.getEsptouchResultTotalLen()); 311 | boolean isSuc = false; 312 | for (int i = 0; i < mParameter.getTotalRepeatTime(); i++) { 313 | isSuc = __execute(generator); 314 | if (isSuc) { 315 | return __getEsptouchResultList(); 316 | } 317 | } 318 | 319 | // wait the udp response without sending udp broadcast 320 | try { 321 | Thread.sleep(mParameter.getWaitUdpReceivingMillisecond()); 322 | } catch (InterruptedException e) { 323 | // receive the udp broadcast or the user interrupt the task 324 | if (this.mIsSuc) 325 | { 326 | return __getEsptouchResultList(); 327 | } 328 | else 329 | { 330 | this.__interrupt(); 331 | return __getEsptouchResultList(); 332 | } 333 | } 334 | this.__interrupt(); 335 | return __getEsptouchResultList(); 336 | } 337 | 338 | } 339 | -------------------------------------------------------------------------------- /src/com/espressif/esp8266_iot/activitys/setupActivity.java: -------------------------------------------------------------------------------- 1 | package com.espressif.esp8266_iot.activitys; 2 | 3 | import android.app.ActionBar; 4 | import android.content.Intent; 5 | import android.content.SharedPreferences; 6 | import android.os.Bundle; 7 | import android.os.StrictMode; 8 | import android.preference.PreferenceManager; 9 | import android.text.Html; 10 | import android.util.Log; 11 | import android.view.Gravity; 12 | import android.view.LayoutInflater; 13 | import android.view.Menu; 14 | import android.view.MenuInflater; 15 | import android.view.MenuItem; 16 | import android.view.View; 17 | import android.view.View.OnClickListener; 18 | import android.view.ViewGroup; 19 | import android.widget.ArrayAdapter; 20 | import android.widget.Button; 21 | import android.widget.EditText; 22 | import android.widget.LinearLayout; 23 | import android.widget.Spinner; 24 | import android.widget.Switch; 25 | import android.widget.TextView; 26 | 27 | import com.espressif.esp8266_iot.GlobalClass; 28 | import com.espressif.esp8266_iot.R; 29 | import com.espressif.esp8266_iot.util.BaseActivity; 30 | 31 | import java.io.IOException; 32 | import java.net.DatagramPacket; 33 | import java.net.DatagramSocket; 34 | import java.net.InetAddress; 35 | import java.net.InetSocketAddress; 36 | import java.net.SocketException; 37 | import java.net.UnknownHostException; 38 | import java.util.prefs.Preferences; 39 | 40 | import static java.net.InetAddress.getByName; 41 | 42 | public class setupActivity extends BaseActivity implements OnClickListener { 43 | private static final String TAG = "setupActivity"; 44 | public static final String PREFS_NAME = "MyPrefsFile"; 45 | 46 | public static TextView mTvApSsid; 47 | 48 | private EditText mEdtApPassword; 49 | private Switch mSwitchIsSsidHidden; 50 | private EspWifiAdminSimple mWifiAdmin; 51 | private Spinner mSpinnerTaskCount; 52 | private EditText mEdtMqttIp; 53 | private EditText mEdtMqttPort; 54 | private EditText mEdtMqttUser; 55 | private EditText mEdtMqttPass; 56 | private Switch mMqttSSL; 57 | 58 | private EditText mEdtUpgradeIp; 59 | private EditText mEdtUpgradePort; 60 | 61 | private EditText mEdtImpulsLength; 62 | 63 | Button mBtnSave; 64 | 65 | //********************************************************************************************** 66 | @Override 67 | public void onCreate(Bundle savedInstanceState) { 68 | Log.d(TAG, "Setup onCreate"); 69 | 70 | super.onCreate(savedInstanceState); 71 | setContentView(R.layout.setup_activity); 72 | StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 73 | StrictMode.setThreadPolicy(policy); 74 | 75 | 76 | // get action bar 77 | ActionBar actionBar = getActionBar(); 78 | // Enabling Up / Back navigation 79 | actionBar.setDisplayHomeAsUpEnabled(true); 80 | //actionBar.setDisplayShowTitleEnabled(false); 81 | 82 | mWifiAdmin = new EspWifiAdminSimple(this); 83 | 84 | mTvApSsid = (TextView) findViewById(R.id.tvApSssidConnected); 85 | 86 | mEdtApPassword = (EditText) findViewById(R.id.edtApPassword); 87 | mSwitchIsSsidHidden = (Switch) findViewById(R.id.switchIsSsidHidden); 88 | //mSpinnerTaskCount = (Spinner) findViewById(R.id.spinnerTaskResultCount); 89 | 90 | mEdtMqttIp = (EditText) findViewById(R.id.edt_mqtt_ip); 91 | mEdtMqttPort = (EditText) findViewById(R.id.edt_mqtt_port); 92 | mEdtMqttUser = (EditText) findViewById(R.id.edt_mqtt_user); 93 | mEdtMqttPass = (EditText) findViewById(R.id.edt_mqtt_pass); 94 | mMqttSSL = (Switch) findViewById(R.id.sw_mqtt_ssl); 95 | 96 | mEdtUpgradeIp = (EditText) findViewById(R.id.edt_Upgrade_ip); 97 | mEdtUpgradePort = (EditText) findViewById(R.id.edt_Upgrade_port); 98 | 99 | mEdtImpulsLength = (EditText) findViewById(R.id.edt_Impuls_length); 100 | 101 | mBtnSave = (net.shikii.widgets.SAutoBgButton) findViewById(R.id.btnSave); 102 | mBtnSave.setOnClickListener(this); 103 | 104 | 105 | } 106 | 107 | //********************************************************************************************** 108 | @Override 109 | protected void onResume() { 110 | super.onResume(); 111 | Log.d(TAG, "Setup onResume"); 112 | final GlobalClass globalVariable = (GlobalClass) getApplicationContext(); 113 | 114 | loadVariablen(); 115 | initSpinner(); 116 | 117 | // display the connected ap's ssid 118 | globalVariable.set_apSsid(mWifiAdmin.getWifiConnectedSsid()); 119 | 120 | if (globalVariable.get_apSsid() != null) { 121 | mTvApSsid.setText(globalVariable.get_apSsid()); 122 | } else { 123 | mTvApSsid.setText(""); 124 | } 125 | if (globalVariable.get_apPassword() != null) { 126 | mEdtApPassword.setText(globalVariable.get_apPassword()); 127 | } else { 128 | mEdtApPassword.setText(""); 129 | } 130 | globalVariable.set_apBssid(mWifiAdmin.getWifiConnectedBssid()); 131 | 132 | globalVariable.set_isSsidHidden(globalVariable.get_isSsidHidden()); 133 | globalVariable.set_isSsidHiddenStr("NO"); 134 | 135 | if (globalVariable.get_isSsidHidden()) { 136 | globalVariable.set_isSsidHiddenStr("YES"); 137 | } 138 | 139 | 140 | mSwitchIsSsidHidden.setChecked(globalVariable.get_isSsidHidden()); 141 | 142 | mEdtMqttIp.setText(globalVariable.get_mqttIp()); 143 | mEdtMqttPort.setText(globalVariable.get_mqttPort()); 144 | mEdtMqttUser.setText(globalVariable.get_mqttUser()); 145 | mEdtMqttPass.setText(globalVariable.get_mqttPass()); 146 | mMqttSSL.setChecked(globalVariable.get_mqttSSL()); 147 | 148 | mEdtUpgradeIp.setText(globalVariable.get_upgradeIp()); 149 | mEdtUpgradePort.setText(globalVariable.get_upgradePort()); 150 | 151 | mEdtImpulsLength.setText(globalVariable.get_ImpulsLengthStr()); 152 | 153 | } 154 | 155 | //********************************************************************************************** 156 | @Override 157 | protected void onStop() { 158 | saveVariablen(); 159 | super.onStop(); 160 | 161 | } 162 | 163 | //********************************************************************************************** 164 | @Override 165 | protected void onDestroy() { 166 | super.onDestroy(); 167 | } 168 | 169 | //********************************************************************************************** 170 | @Override 171 | public void onBackPressed() { 172 | Log.d(TAG, "Setup onBackPressed"); 173 | saveVariablen(); 174 | finish(); 175 | super.onBackPressed(); 176 | } 177 | 178 | //********************************************************************************************** 179 | @Override 180 | public boolean onCreateOptionsMenu(Menu menu) { 181 | MenuInflater inflater = getMenuInflater(); 182 | inflater.inflate(R.menu.menu, menu); 183 | 184 | return true; 185 | //return super.onCreateOptionsMenu(menu); 186 | } 187 | //********************************************************************************************** 188 | /** 189 | * On selecting action bar icons 190 | */ 191 | @Override 192 | public boolean onOptionsItemSelected(MenuItem item) { 193 | int id = item.getItemId(); 194 | //When Search action item is clicked 195 | if (id == R.id.action_main) { 196 | Intent mainIntent = new Intent(this, mainActivity.class); 197 | //Start Product Activity 198 | startActivity(mainIntent); 199 | return true; 200 | } 201 | //When Contact action item is clicked 202 | else if (id == R.id.action_link) { 203 | Intent smartlinkIntent = new Intent(this, smartlinkActivity.class); 204 | //Start Product Activity 205 | startActivity(smartlinkIntent); 206 | return true; 207 | } 208 | return super.onOptionsItemSelected(item); 209 | } 210 | 211 | //********************************************************************************************** 212 | private Integer Bool2Int(Boolean value) { 213 | return value ? 1 : 0; 214 | } 215 | 216 | //********************************************************************************************** 217 | private String Bool2Str(Boolean value) { 218 | int b = value ? 1 : 0; 219 | return String.valueOf(b); 220 | } 221 | 222 | //********************************************************************************************** 223 | @Override 224 | public void onClick(View v) { 225 | final GlobalClass globalVariable = (GlobalClass) getApplicationContext(); 226 | switch (v.getId()) { 227 | case R.id.btnSave: 228 | Log.d(TAG, "mBtnSave is clicked"); 229 | saveVariablen(); 230 | udpSend("255.255.255.255:4," + globalVariable.get_mqttIp() + ";" + globalVariable.get_mqttPort() + ";" + globalVariable.get_mqttUser() + ";" + globalVariable.get_mqttPass() + ";" + Bool2Str(globalVariable.get_mqttSSL()) + ";" + globalVariable.get_upgradeIp() + ";" + globalVariable.get_upgradePort()); 231 | //finish(); 232 | super.onBackPressed(); 233 | break; 234 | } 235 | } 236 | //********************************************************************************************** 237 | private void initSpinner() { 238 | final GlobalClass globalVariable = (GlobalClass) getApplicationContext(); 239 | mSpinnerTaskCount = (Spinner) findViewById(R.id.spinnerTaskResultCount); 240 | int[] spinnerItemsInt = getResources().getIntArray(R.array.taskResultCount); 241 | int length = spinnerItemsInt.length; 242 | Integer[] spinnerItemsInteger = new Integer[length]; 243 | for (int i = 0; i < length; i++) { 244 | spinnerItemsInteger[i] = spinnerItemsInt[i]; 245 | } 246 | ArrayAdapter adapter = new ArrayAdapter(this, 247 | android.R.layout.simple_list_item_1, spinnerItemsInteger); 248 | mSpinnerTaskCount.setAdapter(adapter); 249 | try { 250 | mSpinnerTaskCount.setSelection(Integer.parseInt(globalVariable.get_taskResultCountStr())); 251 | }catch (Exception e) { 252 | e.printStackTrace(); 253 | Log.e(TAG, "Error in initSpinner(): Exception: " + e.getMessage()); 254 | mSpinnerTaskCount.setSelection(0); 255 | } 256 | } 257 | 258 | //********************************************************************************************** 259 | public void loadVariablen() { 260 | final GlobalClass globalVariable = (GlobalClass) getApplicationContext(); 261 | SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0); 262 | if (prefs.contains("Ssid")) 263 | globalVariable.set_apSsid(prefs.getString("Ssid", "")); 264 | if (prefs.contains("Password")) 265 | globalVariable.set_apPassword(prefs.getString("Password", "")); 266 | if (prefs.contains("Bssid")) 267 | globalVariable.set_apBssid(prefs.getString("Bssid", "")); 268 | if (prefs.contains("SsidHidden")) 269 | globalVariable.set_isSsidHidden(prefs.getBoolean("SsidHidden", false)); 270 | if (prefs.contains("SsidHiddenStr")) 271 | globalVariable.set_isSsidHiddenStr(prefs.getString("SsidHiddenStr", "")); 272 | if (prefs.contains("ResultCountStr")) 273 | globalVariable.set_taskResultCountStr(prefs.getString("ResultCountStr", "NO")); 274 | 275 | if (globalVariable.get_isSsidHidden()) { 276 | globalVariable.set_isSsidHiddenStr("YES"); 277 | } 278 | if (prefs.contains("ResultCount")) 279 | globalVariable.set_taskResultCount(prefs.getInt("ResultCount", 1)); 280 | if (prefs.contains("mqttIp")) 281 | globalVariable.set_mqttIp(prefs.getString("mqttIp", "")); 282 | if (prefs.contains("mqttPort")) 283 | globalVariable.set_mqttPort(prefs.getString("mqttPort", "")); 284 | if (prefs.contains("mqttUser")) 285 | globalVariable.set_mqttUser(prefs.getString("mqttUser", "")); 286 | if (prefs.contains("mqttPass")) 287 | globalVariable.set_mqttPass(prefs.getString("mqttPass", "")); 288 | if (prefs.contains("mqttSSL")) 289 | globalVariable.set_mqttSSL(prefs.getBoolean("mqttSSL", false)); 290 | 291 | if (prefs.contains("upgradeIp")) 292 | globalVariable.set_upgradeIp(prefs.getString("upgradeIp", "")); 293 | if (prefs.contains("upgradePort")) 294 | globalVariable.set_upgradePort(prefs.getString("upgradePort", "")); 295 | 296 | if (prefs.contains("ImpulsLength")) 297 | globalVariable.set_ImpulsLengthStr(prefs.getString("ImpulsLength", "")); 298 | } 299 | 300 | //********************************************************************************************** 301 | public void saveVariablen() { 302 | final GlobalClass globalVariable = (GlobalClass) getApplicationContext(); 303 | 304 | globalVariable.set_apSsid(mTvApSsid.getText().toString()); 305 | globalVariable.set_apPassword(mEdtApPassword.getText().toString()); 306 | globalVariable.set_apBssid(mWifiAdmin.getWifiConnectedBssid()); 307 | globalVariable.set_isSsidHidden(mSwitchIsSsidHidden.isChecked()); 308 | globalVariable.set_isSsidHiddenStr("NO"); 309 | globalVariable.set_taskResultCountStr(Integer.toString(mSpinnerTaskCount.getSelectedItemPosition())); 310 | if (globalVariable.get_isSsidHidden()) { 311 | globalVariable.set_isSsidHiddenStr("YES"); 312 | } 313 | globalVariable.set_taskResultCount(mSpinnerTaskCount.getSelectedItemPosition()); 314 | 315 | globalVariable.set_mqttIp(mEdtMqttIp.getText().toString()); 316 | globalVariable.set_mqttPort(mEdtMqttPort.getText().toString()); 317 | globalVariable.set_mqttUser(mEdtMqttUser.getText().toString()); 318 | globalVariable.set_mqttPass(mEdtMqttPass.getText().toString()); 319 | globalVariable.set_mqttSSL(mMqttSSL.isChecked()); 320 | 321 | globalVariable.set_upgradeIp(mEdtUpgradeIp.getText().toString()); 322 | globalVariable.set_upgradePort(mEdtUpgradePort.getText().toString()); 323 | 324 | globalVariable.set_ImpulsLengthStr(mEdtImpulsLength.getText().toString()); 325 | 326 | // We need an Editor object to make preference changes. 327 | // All objects are from android.context.Context 328 | SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); 329 | SharedPreferences.Editor editor = settings.edit(); 330 | editor.clear(); 331 | editor.commit(); 332 | 333 | editor.putString("Ssid", globalVariable.get_apSsid()); 334 | editor.putString("Password", globalVariable.get_apPassword()); 335 | editor.putString("Bssid", globalVariable.get_apBssid()); 336 | editor.putBoolean("SsidHidden", globalVariable.get_isSsidHidden()); 337 | editor.putString("SsidHiddenStr", globalVariable.get_isSsidHiddenStr()); 338 | editor.putInt("ResultCount", globalVariable.get_taskResultCount()); 339 | editor.putString("ResultCountStr", globalVariable.get_taskResultCountStr()); 340 | 341 | editor.putString("mqttIp", globalVariable.get_mqttIp()); 342 | editor.putString("mqttPort", globalVariable.get_mqttPort()); 343 | editor.putString("mqttUser", globalVariable.get_mqttUser()); 344 | editor.putString("mqttPass", globalVariable.get_mqttPass()); 345 | editor.putBoolean("mqttSSL", globalVariable.get_mqttSSL()); 346 | 347 | editor.putString("upgradeIp", globalVariable.get_upgradeIp()); 348 | editor.putString("upgradePort", globalVariable.get_upgradePort()); 349 | 350 | editor.putString("ImpulsLength", globalVariable.get_ImpulsLengthStr()); 351 | 352 | 353 | // Commit the edits! 354 | editor.commit(); 355 | } 356 | 357 | //****************************************************************************************** 358 | void udpSend(String value) { 359 | String messageStr = value; 360 | InetAddress to_ip = null; 361 | DatagramSocket s = null; 362 | final GlobalClass globalVariable = (GlobalClass) getApplicationContext(); 363 | 364 | try { 365 | if (s == null) { 366 | Log.i(TAG, "Create Socket"); 367 | s = new DatagramSocket(null); 368 | s.setReuseAddress(true); 369 | s.setBroadcast(true); 370 | s.bind(new InetSocketAddress(globalVariable.get_RemotePort())); 371 | Log.i(TAG, "Success"); 372 | } 373 | Log.i(TAG, "Send Data:" + messageStr); 374 | String[] separated = messageStr.split(":"); 375 | to_ip = getByName(separated[0]); 376 | messageStr = separated[1]; 377 | int msg_length = messageStr.length(); 378 | byte[] message = messageStr.getBytes(); 379 | DatagramPacket p = new DatagramPacket(message, msg_length, to_ip, globalVariable.get_RemotePort()); 380 | s.send(p); 381 | s.close(); 382 | } catch (SocketException e) { 383 | e.printStackTrace(); 384 | Log.e(TAG, "Error in udpSend(): SocketException: " + e.getMessage()); 385 | } catch (UnknownHostException e) { 386 | e.printStackTrace(); 387 | Log.e(TAG, "Error in udpSend(): UnknownHostException: " + e.getMessage()); 388 | } catch (IOException e) { 389 | e.printStackTrace(); 390 | Log.e(TAG, "Error in udpSend(): IOException: " + e.getMessage()); 391 | } catch (Exception e) { 392 | e.printStackTrace(); 393 | Log.e(TAG, "Error in udpSend(): Exception: " + e.getMessage()); 394 | } 395 | } 396 | 397 | } 398 | -------------------------------------------------------------------------------- /res/layout/setup_activity.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 10 | 11 | 16 | 17 | 24 | 25 | 32 | 33 | 34 | 42 | 43 | 44 | 45 | 52 | 53 | 59 | 60 | 71 | 72 | 73 | 74 | 75 | 83 | 84 | 89 | 90 | 94 | 95 | 102 | 103 | 104 | 111 | 112 | 117 | 118 | 122 | 123 | 128 | 129 | 130 | 131 | 138 | 139 | 146 | 147 | 153 | 154 | 165 | 166 | 167 | 174 | 175 | 181 | 182 | 193 | 194 | 195 | 202 | 203 | 209 | 210 | 214 | 215 | 220 | 221 | 222 | 223 | 230 | 231 | 237 | 238 | 249 | 250 | 251 | 258 | 259 | 265 | 266 | 277 | 278 | 279 | 286 | 287 | 294 | 295 | 301 | 302 | 313 | 314 | 315 | 322 | 323 | 329 | 330 | 341 | 342 | 343 | 350 | 351 | 357 | 358 | 369 | 370 | 371 | 375 | 376 | 384 | 385 | 392 | 393 | 394 | 395 | 396 | 403 | 419 | 420 | 421 | 422 | 423 | 424 | --------------------------------------------------------------------------------