Commit bef77c1e authored by anithghalley's avatar anithghalley
Browse files

update for application week

parent 8e27fdee
Pipeline #315102 passed with stage
in 55 seconds
......@@ -142,7 +142,7 @@ But before programming the board with the attiny45, I tested the sensor with ard
And the Sensor is working fine.
<video width="600" controls>
<source src="../../images/intput/videos/ultrasonic_1.mp4" type="video/mp4">
<source src="../../images/input/videos/ultrasonic_1.mp4" type="video/mp4">
</video>
Next is to connect the Ultrasonic sensor with my board.
......
......@@ -215,7 +215,7 @@ The code can be found at the end this page. After the code is uploaded, switch t
And from the browser we can access the webserver with some interface, provided connected to the same network. The vide
<video width="600" controls>
<source src="../../images/networking_week/videos/networl_test_2.mp4" type="video/mp4">
<source src="../../images/networking_week/videos/network_test_2.mp4" type="video/mp4">
</video>
......
......@@ -53,11 +53,18 @@ The image shows the LED to be controlled by the app over the WiFi connection on
![](../images/interface_application/board.png)
I will be using the same board that I fabricate during the networking week.
## APP
First I created a project in the Mit App Inventor, and added the components as per the apps requirment as shown below.
![](../images/interface_application/my_app.png)
![](../images/interface_application/interface_design.png)
THe two modules in that red square are web and clock.
- Web to connect to the wifi.
- Clock to transmit the signal.
### LED Control.
- To control the LED, I used two buttons to turn on and turn off the led respectively. When ever a button is pressed the expected status of the the LED is shown below the buttons.
......@@ -65,9 +72,31 @@ First I created a project in the Mit App Inventor, and added the components as p
### Servo Control.
- To control the servo, I used a slider to generate a value between 0 to 180. Based on the thump position of the slider the value is selected and when the send angle button is pressed the value is sent to the ESP32 board over the wifi.
The code block for the app is shown below.
The code blocks for the app is shown below.
To connect to the board, an ip address of the board will be entered in the app and wheck check botton is pressed the app will starte communicating with the board. The block below explains the flow.
![](../images/interface_application/connect_block.png)
and the communication between the board and app is maintained by the following app.
![](../images/interface_application/clock.png)
This block is responsible of maintaining the on and off status for LED.
![](../images/interface_application/blocks.png)
And the state is determined by the global varaible coolen bottonState. And similarly we have angle and led to store the data for the Slider and button.
![](../images/interface_application/variable.png)
The slider will control the angle from 0 to 180.
![](../images/interface_application/blockservo.png)
![](../images/interface_application/block_code.png)
### Problems
......@@ -156,12 +185,22 @@ Using the AI Companion feature in the MIT App Inventor the project is easilly li
Now the app is connected on the phone.
![](../images/interface_application/app_phone.PNG)
```
add UI image
```
The video below shows the full process for using the application and interfaing with the components over a wifi network.
<video width="600" controls>
<source src="../../images/interface_application/videos/interface_2.mp4" type="video/mp4">
</video>
## Problem.
### Video of the assignment.
Initially my esp would generate IP address for the device but the app was not able communicate with esp. Therefore to solve the problem I predefined the ip address for the esp and connect the app to thet same address. Which provided higher rate of connection between the devices on a same network.
## Final Files.
- [Mit app inventor filr](https://gitlab.fabcloud.org/academany/fabacademy/2022/labs/bhutan/students/anith-ghalley/-/blob/master/docs/files/application/wifiapp.aia)
- [Mit app inventor filr](https://gitlab.fabcloud.org/academany/fabacademy/2022/labs/bhutan/students/anith-ghalley/-/blob/master/docs/files/application/wifiapp2.aia)
- [Arduino file](https://gitlab.fabcloud.org/academany/fabacademy/2022/labs/bhutan/students/anith-ghalley/-/tree/master/docs/files/application/ESP32_Webserver)
\ No newline at end of file
/*********
Rui Santos
Complete project details at https://randomnerdtutorials.com
*********/
// Load Wi-Fi library
#include <WiFi.h>
#include <ESP32Servo.h>
// Replace with your network credentials
const char* ssid = "SSID";
const char* password = "PASSWORD";
// Set web server port number to 80
WiFiServer server(80);
// Variable to store the HTTP request
String header;
String header1;
// Auxiliar variables to store the current output state
String output4PinState = "n";
// Assign output variables to GPIO pins
const int output4 = 4;
// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0;
// Define timeout time in millisecmds (example: 2000ms = 2s)
const long timeoutTime = 2000;
Servo myServoLeft_1_a;
Servo myServoUltra; //create servo object to cmtrol a servo
// 16 servo objects can be created m the ESP32
int servoLeft_1_a = 32;
String estado = "";
int wait30 = 30000;
int prevAngle = 90;
ESP32PWM pwm;
void setup() {
Serial.begin(115200);
// Initialize the output variables as outputs
pinMode(output4, OUTPUT);
//pinMode(output27, OUTPUT);
// Set outputs to LOW
digitalWrite(output4, LOW);
//digitalWrite(output27, LOW);
// Cmnect to Wi-Fi network with SSID and password
Serial.print("Cmnecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi cmnected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
delay(200);
ESP32PWM::allocateTimer(0);
ESP32PWM::allocateTimer(1);
ESP32PWM::allocateTimer(2);
ESP32PWM::allocateTimer(3);
//
myServoLeft_1_a.setPeriodHertz(50);
myServoLeft_1_a.attach(servoLeft_1_a , 1000, 2000);
delay(100);
}
void loop(){
// If discmnected, try to recmnect every 30 secmds.
if ((WiFi.status() != WL_CONNECTED) && (millis() > wait30)) {
Serial.println("Trying to recmnect WiFi...");
WiFi.disconnect();
WiFi.begin(ssid, password);
wait30 = millis() + 30000;
}
// Check if a client has cmnected..
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.print("New client: ");
Serial.println(client.remoteIP());
// Espera hasta que el cliente envíe datos.
// while(!client.available()){ delay(1); }
/////////////////////////////////////////////////////
// Read the informatim sent by the client.
header = client.readStringUntil('\r');
Serial.println(header);
if (header.indexOf("on") != -1) {digitalWrite(output4, HIGH); estado = "LED4 ON"; Serial.println("On");}
if (header.indexOf("off") != -1){digitalWrite(output4, LOW); estado = "LED4 OFF"; Serial.println("Off");}
if (header.indexOf("servo") != -1){ Serial.println("servo");
int angle = getAngle(header);
//Serial.println(angle);
myServoLeft_1_a.write(angle);
delay(500);
}
//if (req.indexOf("off14") != -1){digitalWrite(LED14, LOW); estado = "LED14 OFF";}
//myservo.write(angle);
//delay(1000);
// Clear the header variable
header1 = "";
// Close the cmnectim
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // Comillas importantes.
client.println(estado); // Return status.
client.flush();
client.stop();
Serial.println("Client disconnected.");
}
// Get servo value from ip
int getAngle(String url){
char servo[15];
char angle[4];
int sub = 11;
url.toCharArray(servo, 15);
for(int i=11; i<15; i++) {
sub = i - 11;
angle[sub] = servo[i];
//Serial.println(servo[i]);
}
//angle[4]= '\0';
int angleValue = atoi(angle);
//Serial.println(angleValue);
return angleValue;
}
// Http Get
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment