Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TFG-JaimeMarques
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jaimarq
TFG-JaimeMarques
Commits
24d49b35
Commit
24d49b35
authored
Mar 17, 2021
by
jaimarq
Browse files
Options
Downloads
Patches
Plain Diff
Subida de carpeta con código
parent
c00cb1fe
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
velostatWiFi/velostatWiFi.ino
+192
-0
192 additions, 0 deletions
velostatWiFi/velostatWiFi.ino
wifi/wifi.ino
+175
-0
175 additions, 0 deletions
wifi/wifi.ino
with
367 additions
and
0 deletions
velostatWiFi/velostatWiFi.ino
0 → 100644
+
192
−
0
View file @
24d49b35
// pines analogicos
/*
* espD32 LOLIN
* ADC1_0 GPIO VN 5 NO
* ADC1_3 GPIO VP 4 NO
* ADC1_4 GPIO 32 8 y
* ADC1_5 GPIO 33 9 y
* ADC1_6 GPIO 34 6 y
* ADC1_7 GPIO 35 7 NO
* ADC2_0 GPIO 04 26 y
* ADC2_1 GPIO 00 25 y (poco rango 3400-4095)
* ADC2_2 GPIO 02 24 y
* ADC2_3 GPIO 15 23 y
* ADC2_4 GPIO 13 16 y
* ADC2_5 GPIO 12 14 y
* ADC2_6 GPIO 14 13 y
* ADC2_7 GPIO 27 12 y
* ADC2_8 GPIO 25 10 y
* ADC2_9 GPIO 26 11 y
*
* 3V -> velostat comun -> Salida1 3V --^v^v Velostat -+---+---+
* -> Analog | | |
* -> R10K -> GND Analog1--+ +---|---Analog2
* Gnd-------10K ^v^v----+ | |
Gnd-------10K ^v^v--------+ |
Gnd-------10K ^v^v------------+---Analog3
*
*/
/*
* This sketch sends data via HTTP GET requests to data.sparkfun.com service.
*
* You need to get streamId and privateKey at data.sparkfun.com and paste them
* below. Or just customize this script to talk to other HTTP servers.
*
*/
#include
<WiFi.h>
#include
<HTTPClient.h>
const
char
*
ssid
=
"MOVISTAR_6160"
;
const
char
*
password
=
"yLvf9XTbTtpUpNPp7mjB"
;
const
char
*
host
=
"arduiacob.i234.me"
;
const
char
*
hosturl
=
"http://arduiacob.i234.me/velostat/datos.php"
;
const
char
*
privateKey
=
"...................."
;
// Usamos GPIO para determinar el numero del pin
// LOLIN D32 WEMOS
//int pinanalog[] = {32,33,34,4,2,15,13,12,14,27,25,26};
// WEMOS LOLIN32
int
pinanalog
[]
=
{
36
,
39
,
32
,
33
,
34
,
35
};
//14,12,13,25,26,27};
//int pinanalog[] = {32,33,34,4,2,15,27,25,26};
//int pinanalog[] = {13,12,14,27,25,26,32};
// int pinanalog[] = {35,0};
// milisegundos entre registros
int
inter_reg
=
100
;
const
int
n
=
6
;
// numero de sensores a activar
// limite de datos = n * limit
const
int
limit
=
600
;
// Array para guardar 1000 registros de cada sensor
unsigned
int
value1
[
limit
][
n
+
1
]
;
// Array para guardar 1000 registros de cada sensor
unsigned
int
value2
[
limit
][
n
+
1
]
;
// para saber si los registros es value1 o value2
byte
value
=
1
;
// Posicion de cada registro
int
pos
=
0
;
long
t
=
0
;
int
bufferpos
=
0
;
// marca de tiempo
long
ahora
=
0
;
long
antes
=
0
;
void
setup
()
{
Serial
.
begin
(
115200
);
// WiFi
delay
(
10
);
// We start by connecting to a 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"
);
Serial
.
println
(
"IP address: "
);
Serial
.
println
(
WiFi
.
localIP
());
// Iniciando entradas analógicas
for
(
int
i
=
0
;
i
<
n
;
i
++
){
pinMode
(
i
,
INPUT
);
Serial
.
print
(
pinanalog
[
i
]);
}
// Serial.println('Iniciando lectura');
// Serial.println('...');
// delay(1000);
}
void
loop
()
{
//Serial.println();
// for (int i=0; i<n; i++){
// value1[pos] = analogRead(pinanalog[i]);
// pos ++ ;
//Serial.print(analogRead(pinanalog[i]));
// delay(50);
//Serial.print(',');
// }
// Serial.println();
generaDatos
();
}
void
generaDatos
(){
/*
* DATOS:
* pos=0 {[1],[1234,1244,2355,244,523,2343,2312,313,355]}
* pos=1 {[7],[1234,1244,2355,244,523,2343,2312,313,355]}
* pos=2 {[14],[1234,1244,2355,244,523,2343,2312,313,355]}
*/
ahora
=
millis
();
if
(
ahora
-
antes
>
inter_reg
){
if
(
pos
<
(
limit
))
{
t
=
millis
();
value1
[
pos
][
0
]
=
millis
();
//Serial.print(value1[pos][0]);
//Serial.print(",");
for
(
int
i
=
0
;
i
<
n
;
i
++
){
value1
[
pos
][
i
+
1
]
=
analogRead
(
pinanalog
[
i
])
;
Serial
.
print
(
value1
[
pos
][
i
+
1
]);
Serial
.
print
(
","
);
}
Serial
.
println
();
pos
++
;
antes
=
t
;
}
else
{
pos
=
0
;
// value2 = value1;
if
(
bufferpos
==
limit
-
1
)
conexServer
();
else
{
while
(
bufferpos
<
limit
)
cargabuffer
();
conexServer
();
}
}
}
cargabuffer
();
}
void
cargabuffer
(){
int
pos2
;
if
(
pos
!=
0
)
pos2
=
pos
;
else
pos2
=
limit
;
for
(
int
i
=
bufferpos
;
i
<
pos2
;
i
++
){
for
(
int
z
=
0
;
z
<
n
+
1
;
z
++
){
value2
[
i
][
z
]
=
value1
[
i
][
z
];
}
}
bufferpos
=
pos2
-
1
;
}
This diff is collapsed.
Click to expand it.
wifi/wifi.ino
0 → 100644
+
175
−
0
View file @
24d49b35
void
conexServer
(){
metodoPOST
();
}
void
metodoPOST
(){
String
content
;
// We now create a URI for the request
content
=
"value=["
;
for
(
int
z
=
0
;
z
<
limit
;
z
++
)
{
content
+=
"["
;
content
+=
value2
[
z
][
0
];
content
+=
","
;
for
(
int
i
=
1
;
i
<
n
+
1
;
i
++
)
{
content
+=
value2
[
z
][
i
];
if
(
i
<
n
)
content
+=
","
;
}
content
+=
"]"
;
if
(
z
<
limit
-
1
)
content
+=
","
;
}
content
+=
"]"
;
//content = "value=[[12,1,2,3,4,5,6,7,8,9],[17,1,2,3,4,5,6,7,8,9],[23,1,2,3,4,5,6,7,8,9]]";
HTTPClient
http
;
// Your Domain name with URL path or IP address with path
http
.
begin
(
hosturl
);
// Specify content-type header
http
.
addHeader
(
"Content-Type"
,
"application/x-www-form-urlencoded"
);
// Data to send with HTTP POST
String
httpRequestData
=
content
;
// Send HTTP POST request
int
httpResponseCode
=
http
.
POST
(
httpRequestData
);
/*
// If you need an HTTP request with a content type: application/json, use the following:
http.addHeader("Content-Type", "application/json");
// JSON data to send with HTTP POST
String httpRequestData = "{\"api_key\":\"" + apiKey + "\",\"field1\":\"" + String(random(40)) + "\"}";
// Send HTTP POST request
int httpResponseCode = http.POST(httpRequestData);
*/
Serial
.
print
(
"HTTP Response code: "
);
Serial
.
println
(
httpResponseCode
);
// Free resources
http
.
end
();
}
void
metodoGET
(){
String
content
;
Serial
.
print
(
"connecting to "
);
Serial
.
println
(
host
);
// Use WiFiClient class to create TCP connections
WiFiClient
client
;
const
int
httpPort
=
80
;
if
(
!
client
.
connect
(
host
,
httpPort
))
{
Serial
.
println
(
"connection failed"
);
return
;
}
// // We now create a URI for the request
String
url
=
"/velostat/datos.php"
;
url
+=
"?private_key="
;
url
+=
privateKey
;
url
+=
"&value=["
;
// ahora hay que recorrer value2
// url += value2;
for
(
int
z
=
0
;
z
<
limit
;
z
++
)
{
url
+=
"["
;
url
+=
value2
[
z
][
0
];
url
+=
","
;
for
(
int
i
=
1
;
i
<
n
+
1
;
i
++
)
{
url
+=
value2
[
z
][
i
];
if
(
i
<
n
)
url
+=
","
;
}
url
+=
"]"
;
if
(
z
<
limit
-
1
)
url
+=
","
;
}
url
+=
"]"
;
Serial
.
print
(
"Requesting URL: "
);
Serial
.
println
(
url
);
// This will send the request to the server
client
.
print
(
String
(
"GET "
)
+
url
+
" HTTP/1.1
\r\n
"
+
"Host: "
+
host
+
"
\r\n
"
+
"Connection: close
\r\n\r\n
"
);
unsigned
long
timeout
=
millis
();
while
(
client
.
available
()
==
0
)
{
generaDatos
();
if
(
millis
()
-
timeout
>
(
inter_reg
-
1
)
*
limit
)
{
Serial
.
println
(
">>> Client Timeout !"
);
client
.
stop
();
return
;
}
}
// Read all the lines of the reply from server and print them to Serial
while
(
client
.
available
())
{
String
line
=
client
.
readStringUntil
(
'\r'
);
Serial
.
print
(
line
);
}
Serial
.
println
();
Serial
.
println
(
"closing connection"
);
}
void
metodoPOST2
(){
Serial
.
print
(
"connecting to "
);
Serial
.
println
(
host
);
// Use WiFiClient class to create TCP connections
WiFiClient
client
;
const
int
httpPort
=
80
;
if
(
!
client
.
connect
(
host
,
httpPort
))
{
Serial
.
println
(
"connection failed"
);
return
;
}
// // We now create a URI for the request
String
url
=
"/velostat/datos.php"
;
String
content
=
"value=["
;
// ahora hay que recorrer value2
// url += value2;
for
(
int
z
=
0
;
z
<
limit
;
z
++
)
{
content
+=
"["
;
content
+=
value2
[
z
][
0
];
content
+=
","
;
for
(
int
i
=
1
;
i
<
n
+
1
;
i
++
)
{
content
+=
value2
[
z
][
i
];
if
(
i
<
n
)
content
+=
","
;
}
content
+=
"]"
;
if
(
z
<
limit
-
1
)
content
+=
","
;
}
content
+=
"]"
;
Serial
.
print
(
"Requesting URL: "
);
Serial
.
println
(
url
);
Serial
.
print
(
content
);
// This will send the request to the server
client
.
print
(
String
(
"POST "
)
+
url
+
" HTTP/1.1
\r\n
"
+
"Host: "
+
host
+
"
\r\n
"
+
content
+
"
\r\n
"
+
"Content-Type: application/x-www-form-urlencoded
\r\n
"
+
"Connection: close
\r\n\r\n
"
);
unsigned
long
timeout
=
millis
();
while
(
client
.
available
()
==
0
)
{
generaDatos
();
if
(
millis
()
-
timeout
>
(
inter_reg
-
1
)
*
limit
)
{
Serial
.
println
(
">>> Client Timeout !"
);
client
.
stop
();
return
;
}
}
// Read all the lines of the reply from server and print them to Serial
while
(
client
.
available
())
{
String
line
=
client
.
readStringUntil
(
'\r'
);
Serial
.
print
(
line
);
}
Serial
.
println
();
Serial
.
println
(
"closing connection"
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment