Code
#include
const char* ssid = “Phamson”;
const char* password = “phamtheson”;
WiFiServer server(80);
void setup() {
Serial.begin(115200); //Default Baud Rate for NodeMCU
delay(10);
pinMode(2, OUTPUT); // Connect Relay to NodeMCU’s D4 Pin
digitalWrite(2, 0);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
Serial.println(“”);
Serial.println(“WiFi connected”);
// Start the server
server.begin();
Serial.println(“Server started”);
// Print the IP address
Serial.println(WiFi.localIP());
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
// Wait until the client sends some data
Serial.println(“new client”);
while(!client.available()){
delay(1);
String req = client.readStringUntil(‘\r’);
Serial.println(req);
client.flush();
int val;
if (req.indexOf(“/gpio/0”) != -1)
val = 0;
else if (req.indexOf(“/gpio/1”) != -1)
val = 1;
else {
Serial.println(“invalid request”);
client.stop();
return;
// Set GPIO2 according to the request
digitalWrite(2, val);
client.flush();
String s = “HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n
\r\n
\r\nGPIO is now “;
s += (val)?”high”:”low”;
s += “”;
————————————————————————————
DV1 – Nhận vẽ mạch thuê ONLINE Altium Designer/ Orcad 9.2/ Protues nhanh trong ngày
———————————————————————————–
DV2 – Mua linh kiện về làm mạch nhanh – Miễn phí Ship
DV3 – Kênh youtube chia sẻ kiến thức điện tử thực hành ngay
DV4 – Kênh cộng đồng Facebook Điện Tử ChipKool
eChipKool – Chia sẻ kiến thức Kết Nối đam mê điện tử
Hello.
Is there a way in MIT App Inventor to check if the WIFI connection has changed (what I mean by that is if it has changed from WIFI 1 to WIFI 2 but NOT to check if the WIFI is on or off)
Thanks to anyone who would like to help me!
Hello.
Is there a way in MIT App Inventor to check if the WIFI connection has changed (what I mean by that is if it has changed from WIFI 1 to WIFI 2 but NOT to check if the WIFI is on or off)
Thanks to anyone who would like to help me!
Use the extension:
Thanks for the reply but how do I use the extension?I have it downloaded and added into my project.Can you teach me how to use it?
Like for you to show me blocks that are functioning.
Did you read the page you were referred to ?
https://puravidaapps.com/wifi.php
All blocks are shown and described in some detail
Yes, I did. I even downloaded the aia file but I don’t get how that works.
get the current SSID and store it in a global variableuse a clock component and check regularly if the current SSID is still the same as the stored ssidif not, it has changed
A very good way to learn App Inventor is to read the free Inventor’s Manual here in the AI2 free online eBook http://www.appinventor.org/book2 … the links are at the bottom of the Web page. The book ‘teaches’ users how to program with AI2 blocks.There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro and the aia files for the projects in the book are here: http://www.appinventor.org/bookFilesHow to do a lot of basic things with App Inventor are described here: http://www.appinventor.org/content/howDoYou/eventHandling .
Also do the tutorials http://appinventor.mit.edu/explore/ai2/tutorials.html to learn the basics of App Inventor, then try something and follow the Top 5 Tips: How to learn App Inventor
Taifun
Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.
I was thinking to do the same but I really didn’t do it because I didn’t know what the SSID is. Thanks.
protip: read the documentation App Inventor Extensions: WiFi | Pura Vida Apps
SSID
Get current WiFi SSID (Service Set Identifier).
and use Google: what is SSID – Google Search
SSID stands for Service Set IDentifier and is your network’s name. If you open the list of Wi-Fi networks on your laptop or phone, you’ll see a list of SSIDs .
Taifun
And how do I get the stored SSID?is it by using this block?
Because what I want to do is if it has changed the WIFI connection, it would appendValueToList saying “reconnecting” or something, so that the connection won’t be lost.
So, with that block can I store the connection it currently has and when it has changed I can compare it and appenedValueToList?
you stored it previously yourself in a global variable or TinyDBTaifun
See the App Inventor Extensions document about how to use an App Inventor Extension.For questions about this extension or bug reports please start a new thread in the App Inventor community. Thank you.For feature requests please contact me by email. To be a sponsor of a new method already is possible starting from only 10 USD! With your contribution you will help the complete App Inventor community. Thank you.
Dec 22th, 2015: Version 1: initial release.
July 7th, 2016: Version 2: macAddress method added.
Aug 11th, 2016: Version 2a: avoid DX execution failed error: build each extension separately
Nov 27th, 2016: Version 3: BSSID method added
Feb 25th, 2017: Version 3a: bugfix IllegalArgumentException: Receiver not registered: null while switching screens
May 10th, 2017: Version 3b: bugfix IllegalArgumentException: Receiver not registered while switching screens
Aug 14th, 2017: Version 4: correspondingRSSIs, SignalStrength, ConnectionInfo, Is5GHzBandSupported added
Aug 16th, 2017: Version 5: correspondingBSSIs added
Dec 6th, 2017: Version 5a: bugfix configuredSSIDs, see also here. Thank you Edgar for the error report.
Dec 14th, 2017: Version 5b: bugfix ConnectSSID, see also here. Thank you again Edgar for the error report.
Apr 8th, 2018: Version 6: new method AccessPointIP added
Apr 13th, 2018: Version 7: connect without password
Aug 29th, 2018: Version 8: Disconnect method added
Nov 6th, 2018: Version 9: Dnsservers method added
Jan 23th, 2019: Version 10: SDK 26 update: dangerous permission android.permission.ACCESS_COARSE_LOCATION removed. What is a dangerous permission? The method AvailableSSIDs including its corresponding event have been removed.
Jan 28th, 2019: Version 11: AvailableSSIDs added again. Additionally example project provided about how to use it together with the location sensor and GPS enabled.
Oct 21th, 2019: Version 12: AfterWifiNegotiation event added
Oct 21th, 2019: Version 13: RemoveSSID added
Oct 21th, 2019: Version 14: LocalIP: returns wifi ip if its enabled else the cellular one
May 25th, 2021: Version 14 recompiled, see also here.
Nov 12th, 2021: Version 15: android.permission.ACCESS_NETWORK_STATE added for App Inventor nb188 release, see also here.
Aug 31st, 2023:
Version 16: ACCESS_FINE_LOCATION and WRITE_SETTINGS permissions added,ConnectSSID method for Android >= 10 uses the network request API, see also hereHaveSystemWritePermission and ApiLevel methods added,IsGpsEnabled, IsLocationPermissionGranted and RequestLocationPermission method added,MacAddress method removed, does not work for Android M, see also hereRemoveSSID method removed, suppressWarning properties replaced by ErrorOccurred eventNote: this version of the extension is not compatible with earlier versions. You therefore have to remove the extension from your project and then import it as new extension.
Dec 10th, 2023: Version 16a:
Extension rebuilt to avoid “ERROR: DX returned an error code” for projects, having 2 extensions or more which use proguard to obfuscate their code,
see also Pull request 3004.
Some useful blocks to use in a wireless lan.Required permissions: android.permission.ACCESS_WIFI_STATE, android.permission.CHANGE_WIFI_STATE, android.permission.ACCESS_NETWORK_STATE, android.permission.ACCESS_FINE_LOCATION, android.permission.WRITE_SETTINGS
Returns whether Success Message should be suppressed.
Specifies whether Success Message should be suppressed.
Return the local IP Address. Returns wifi ip if its enabled else the cellular one.Sponsor of this block is Marius. Thank you!
Return the MAC Address of the device.Sponsor of this block is Niko. Thank you!
Get current WiFi state: true or false.
Enable WiFi.You can hide the success message after setting the suppressSuccessMessage property to false.Note: starting from Android 10, it is not possible anymore to enable Wifi programmatically, see also this stackoverflow answer, therefore a dialog for the user will be provided, see also this Activity Starter solution.
Disable WiFi.You can hide the success message after setting the suppressSuccessMessage property to false.Note: starting from Android 10, it is not possible anymore to disable Wifi programmatically, see also this stackoverflow answer, therefore a dialog for the user will be provided, see also this Activity Starter solution.
Get current WiFi SSID (Service Set Identifier).Note: to be able to test this block, you have to build the app, because the permission CHANGE_WIFI_STATE is not available in the companion app.Note: Precondition to use this method is to grant location permission. Also GPS must be enabled. See the example project about how to use it..
Get current WiFi BSSID (the MAC address of the access point).Thank you burrowmoor for being the sponsor of this method.Note: to be able to test this block, you have to build the app, because the permission CHANGE_WIFI_STATE is not available in the companion app.Note: Precondition to use this method is to grant location permission. Also GPS must be enabled. See the example project about how to use it..
Get a list of available SSIDs (Service Set Identifiers). WiFi must be enabled for this.Note: to be able to test this block, you have to build the app, because the permission CHANGE_WIFI_STATE is not available in the companion app.Note: Precondition to use this method is to grant location permission. Also GPS must be enabled. See the example project about how to use it..
Note: Android will get more and more restricted. In a future Android release the AvailableSSIDs method will stop working, see also this note in the Android documentation: “The ability for apps to trigger scan requests will be removed in a future release.”
Get current connection info.For details, see also WiFiInfo documentation.
Check, if 5 GHz Band is supported. Returns true or false.
Get signal strength (RSSI) in a range between 0 and 100.This algorithm is used to calculate the signal strength..
Get IP address of the access point.Thank you Eric for being the sponsor of this method.
Return a list of DNS servers (primary and secondary) of the current network.Note: The method returns the IP address of the gateway router when DNS is not configured inside the router.Thank you Gabriel for being the sponsor of this method.
Connect to a SSID (Service Set Identifier). Available for Android >= 10.The new peer to peer API to bootstrap configuration for secondary devices is used, which is available starting from Android 10, see also here. This API requires the permission WRITE_SETTIMGS.Note: Creating a connection using this API does not provide an internet connection to the app or to the device!!!Bypassing user approvalOnce the user approves a network to connect to in response to a request from a specific app, the device stores the approval for the particular access point. If the app makes a specific request to connect to that access point again, the device skips the user approval phase and automatically connects to the network. If the user chooses to forget the network while connected to a network requested by the API, then this stored approval for that combination of app and network is removed, and any future request from the app must be approved by the user again.Note: to be able to test this block, you have to build the app, because the permission WRITE_SETTINGS is not available in the companion app.
Disconnect. Available for Android >= 10.Note: after disconnecting the device might reconnect automatically to the next available known network.Thank you Wei Zheng for being the sponsor of this method.
Returns the API Level of the device.
Check, whether we have system write permission or not. Returns true or false. In case of false, the Android write settings menu of the app will be opened automatically.
Returns true, if location permission have been granted.
Request location permission. Required for SSID, BSSID, AvailableSSIDs methods.
Event indicating that Available SSIDs (Service Set Identifiers) have been scanned.A list of the available SSIDs is provided in parameter availableSSIDs. The SSID having the best signal is provided in parameter bestSSID. A list of the corresponding RSSIs is provided in parameter correspondingRSSI. A list of corresponding BSSIs is provided in parameter correspondingBSSIs.Thank you Tal for being the sponsor of the correspondingRSSI and correspondingBSSI functionality.
Event indicating that network is available. Available starting from Android 10.
Event indicating that error occurred.
Version 16 tested successfully on Samsung Galaxy A54 running Android 13.
Q1: I used Taifun Wifi Extension to search & connect to Available wifi network. But my problem rise when I connect using SSID & PASSWORD,
the connection never succeeds. But if I set My access point to open network & I remove password from connect extension, the connection establish
but only for few seconds & my phone connecting to another configured wifi network. My phone use android 8 api 26.A: Problem solved. The SSID NAME in my case it must be between 6 to 11 character, the SSID NAME must be start with Character (do not use number for first character), the Password must at least 9 character . Now connection are made successfully. Thank you pjack2021.Q2: After successfully connecting, when I go to the Android wifi settings. I click on my wifi (to see the information) and there is nothing. IP address, subnet mask, etc. but the connection to the wifi network is successful.A: Yes, this is the correct behavior for devices starting from Android 10. See also the explanation from Google here: Network request API: targets apps that need to connect to a peer device, such as when configuring an IoT device or transferring files to a camera. In such cases, the peer device starts up a SoftAP and the API allows the app to guide the user to connect to the device. The resulting network is not intended to provide internet access, can’t be used by the system, and can’t be used by any app except the configuring app. User selection and approval is required the first time a connection is made to a new peer. Intended for IoT configuration apps and IoT file transfer apps..
The test app is available in Google Play. You can test the example following these steps
You can buy this extension (aix file).With your payment you accept the terms and conditions below.Payment options
1. Please transfer 12 USD via Paypalto Pura Vida Apps
2.
After having received your payment I will be happy to send the download link to you. Please let me know your Google account!
I usually will send the download link not later than 24 hours after having received your payment.Thank you! Taifun
I still provide the latest free version 15 of the extension here without support. There might be permission issues for some methods. Also the Connect method will not work anymore for newer devices.
It is recommended to use the paid version instead.Download TaifunWiFi extension (aix file) Version 15Download Wifi example project (aia file)Back to top of page …
hello, I have my application that works well, it connects to wifi, no problem (both my box and APPointesp8266). I’m looking to make a screen where all the possible connections are displayed, then choose and enter the password.I looked on the site in other sites, I found nothing is it possible? (as in Bleutooth where we are looking for devices)Thanks for reading
hello, I have my application that works well, it connects to wifi, no problem (both my box and APPointesp8266). I’m looking to make a screen where all the possible connections are displayed, then choose and enter the password.
you might want to try the wifi extensionhttps://puravidaapps.com/wifi.phpsee also the extensions directory here https://puravidaapps.com/extensions.phpTaifun
Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.
Hello, I studied the code it works, the application connect. When I connect to Access point on the esp8266, the connection comes back to that of origne, “message no internet access” which is normal. How to do?thank you.
sorry, I do not understand… you might want to elaborate…Taifun
sorry it’s my phone who does this, as the connection does not have internet access, it changes network, without notifying me.on the other hand when I am in development, I have get SSID,when I make built apk impossible, it asks me for the authorization that the apk uses wifi, I answer yes ?. It connects well.
Hello,I’m still looking for a solution for my SSID problem.When I am in development I have the SSID of the network connected to my telephone companion.when I build the application and then launch it, I cannot have the network SSID connected.I forgot something?thank you
Hello again,
I have now moved on to some wifi identification and am using your wifi manager ext
In particular .AvailableSSIDs which is working great! However it has a delay from calling to listing SSID’s of about (3 seconds).
Is there any way of reducing that time delay? If so, ill be happy to sponsor of course.
Cheers
Ric
scanning takes its time… the only thing to make this faster is to use a faster device…
however what I could implement is to add a Progress event, which could provide each new found SSID immediately similar to the Progress event in the packagemanager extension
EDIT: sorry, I promised too much…the scanning first must be executed, then the complete result is given back, it seems to be there is not possibility to get a progress meanwhile scanning…
Taifun
Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.
Hello @Taifun , I just Try your AvailableSSID.aia with the wifi extension on it, and worked well.but I unable to parsing SSID that I want by giving the event “When GotAvailableSSIDs ” do text comparelike picture bellow
The result it always false “Access point unavailable” , even I know my access point exist.
It test with of AvailableSSIDs the result is False it mean The Result Value of availableSSIDs not strings or mybe integer is this correct?
how to get ride of my problem , to extract SSID that I Want in availableSSIDs
Thanks
Ok I resolved my problem
great… and next time please ask in the community of the builder you are usingthank you
Taifun
Open the Google Play store or Apple App store on your phone or tablet, or use the buttons below to open the corresponding page:
After downloading, step through the instructions to install the Companion app on your device. You need to install the MIT App Inventor Companion app only once, and then you can leave it on your phone or tablet for whenever you use App Inventor. Note: There are some differences between the Android and iOS versions. Please review this page for more details.
Alternatively, you can scan the following QR codes to get either the iOS or Android app:
For iOS, scan this code to go to the Companion app on the Apple App Store.
For Android, scan this code to download the Android .APK file for the Companion app directly to your device. (Using an .APK file requires sideloading the app on your device and updating the app manually in the future.)
App Inventor will automatically show you the app you are building, but only if your computer (running App Inventor) and your device (running the Companion) are connected to the same Wi-Fi network. See a more detailed explanation of this here.
Go to App Inventor and open a project (or create a new one — use Project > Start New Project and give your project a name).
Then Choose “Connect” and “AI Companion” from the top menu in your browser:
A dialog with a QR code will appear on your PC screen. On your device, launch the MIT App Companion app just as you would do any app. Then click the “Scan QR code” button on the Companion, and scan the code in the App Inventor window:
Within a few seconds, you should see the app you are building on your device. It will update as you make changes to your design and blocks, a feature called “live testing.”
If you have trouble scanning the QR code or your device does not have a scanner, type the code shown on the computer into the Companion’s text area on your device exactly as shown. The code is directly below where the screen on your PC shows “Your code is” and consists of six characters. Type the six characters and choose the orange “Connect with code.” Do not type an Enter or carriage return: type just the six characters followed by pressing the orange button.
If your app does not appear on your device, the most likely problems are:
A feature of AppInventor allows users to connect a device to a PC over Wi-Fi to test their apps. Below we explain in more detail how this process works.
To use the AppInventor connection over Wi-Fi, a user must download the MIT AI2 Companion App via the Google Play Store or Apple App Store, and install it directly to your phone.
The MIT AI2 Companion allows users to make a connection between an Android or iOS device and a PC over the MIT RendezVous Server.
The phone or table must be using Wi-Fi and not the cell network for Internet connectivity.
1. Your PC checks in with a 6-character code generated by the MIT AI2 Companion
2. MIT RendezVous Server records the IP address of your PC
3. Your device checks in with a 6-character code
4. MIT RendezVous Server records the IP address of your phone
5. MIT RendezVous Server tells the device and computer with the matching 6-character code the other’s IP address
6. Device and computer communicate directly using IP
Ideally our network situation should look like this:
Try the following steps to troubleshoot your wireless connection:
1. Try to reach http://rendezvous.appinventor.mit.edu from your PC
2. Try to reach http://rendezvous.appinventor.mit.edu from your device
3. If the steps above both work, try using the “ping” command to ping to the IP Address of the phone (displayed by the MIT AI2 Companion in its startup window). If you are using windows, type “ping” + *IP address of the phone* in cmd.exe window, if you are using mac or linux, type type “ping” + *IP address of the phone* in terminal window. Detailed instruction see http://www.wikihow.com/Ping-an-IP-Address
4. If all of these steps succeed and Wireless App Inventor still doesn’t work, then there may be a firewall between the computer and phone that is blocking ports 8001 and 9987. If you have a “telnet” program you can attempt to telnet from the computer to the phone on these ports. If the connection won’t complete, then there is likely a firewall in place that is blocking connections to the phone
If you do not pass step 4, your network most likely looks like this.
Many networks have firewalls set up that block connections to the phone. A way to get around this is to use your own or a local computer as a Wi-Fi router and have all computers and devices using App Inventor connect to the network using the new router. For detailed instruction setting up a computer as a router, see http://www.wikihow.com/Create-a-Wireless-Network
Check that your device is connected to Wi-Fi and not the cell network. On some devices and in some locations, even with Wi-Fi enabled, the phone continues to use the cell network. If this is happening to you, you can disable mobile networking (cell phone carrier based Internet connectivity) from your device’s settings menu.
Hey! I’m studying computer engineering and I’m doing an extension project. My team needs to create a smart watch and I’m responsible for making the app. So we will use wifi connection but I can’t find anything about how to use esp32 wifi connection for MIT app inventor. Can someone please help me? We need to get the information from the esp32 and take it to the app. I would be very grateful to anyone who can help.
It’s not clear to me that an extension would be necessary. If you’re communicating with the ESP32 over Wifi you can just use the Web component built in to App Inventor.
the problems is that i don’t know how to use de Web component in MIT app inventor. It would be awesome if someone could help me giving a little tutorial.
It looks like you forgot to search this community… there are plenty of threads about esp32https://community.appinventor.mit.edu/search?q=esp32%20web
A very good way to learn App Inventor is to read the free Inventor’s Manual here in the AI2 free online eBook App Inventor 2 Book: Create Your Own Android Apps … the links are at the bottom of the Web page. The book ‘teaches’ users how to program with AI2 blocks.There is a free programming course here Course In A Box and the aia files for the projects in the book are here: App Inventor 2 Book: Create Your Own Android AppsHow to do a lot of basic things with App Inventor are described here: How do you…? .
Also do the tutorials http://appinventor.mit.edu/explore/ai2/tutorials.html to learn the basics of App Inventor, then try something and follow the Top 5 Tips: How to learn App Inventor
Taifun
Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.
Bài viết sẽ hướng dẫn các bạn cách tạo một App đơn giản và điều khiển các thiết bị trong gia đình thông qua NodeMCU ESP8266. Để có thể nắm rõ hơn các bạn có thể tìm đọc các bài viết liên quan đến dự án.
Tạo App Android bằng MIT APP INVENTOR
Để có thể tạo một App Android bằng MIT app inventor chúng truy cập vào link để tạo dự án nhé: http://appinventor.mit.edu
Bước đầu tiên các bạn Click vào Projects chọn “Start new project” để tạo một dự án mới.
Tiếp theo chúng ta cần đặt tên cho dự án.
Ở bên tay trái màn mình các bạn, chúng ta Click vào Button dùng để bật tắt thiết bị. Ở đây mình sẽ chọn 2 nút và đặt là “ON” và “OFF”.
Để có thể chỉnh sửa các thông số của Button các bạn Click vào và nó sẽ xổ ra các trường thông tin. Ở đây các bạn có thể đặt lại tên cho Button ở phần Text …
Tiếp theo, các bạn chọn mục Connectivity và cho Web và kéo thả vào Viewer nhé.
Sau khi đã cấu hình cho các Button và Web ta chọn vào Block để chuyển qua lập trình kéo thả Block.
Click vào “Button 1” chọn phần mà mình đã khoanh đỏ và kéo chúng vào vùng lập trình.
Tiếp tục, ta chọn “Web1” và kéo Block đã được đánh dấu. Ở phần này chúng ta sẽ cấu hình địa chỉ IP Web.
Chọn mục “Text” kéo block được khoanh đỏ vào vùng lập trình.
Tiếp theo ở mục Web1 chọn Block “Call Web.Get”.
Để biết được địa chỉ IP của NodeMCU ESP8266 ta cần nạp Code và bật Monitor lên xem nhé. Code mình để cuối bài viết các bạn tải về và
thực hiện nhé. Ở đây địa chỉ IP của mình là: 192.168.88.106
- http://192.168.88.106/gpio/1
- http://192.168.88.106/gpio/0
Các bạn kéo thả các Block lại với nhau giống như trên màn hình nhé.
Để có thể tải dự án về điện thoại, các bạn vào mục Build chọn App (project QR code for apk).
Quét mã QR code xuất hiện trên màn hình. Và các bạn tiến hành cài đặt App vào điện thoại nhé.
Như vậy là đã xong các bạn có thể điều khiển bật tắt thiết bị trên App điện thoại rồi.
Keywords searched by users: mit app inventor 2 wifi
Categories: Khám phá 36 Mit App Inventor 2 Wifi
See more here: kientrucannam.vn
See more: https://kientrucannam.vn/vn/