#define potarPIN A0
float last_temp;
float x;
float y;
void setup() {
//start serial
Serial.begin(9600);
//set calcul for x and y
setXandY(10,30);
//set potentiometer
pinMode(potarPIN, INPUT);
}
void loop() {
// read POTAR
float wanted_temp = toTemp(analogRead(potarPIN));
Serial.println(x,10);
if(last_temp!=wanted_temp){
//send data to server
#include <SPI.h>
#include <WiFiNINA.h>
#include <WiFi.h>
#define potarPIN A0
char ssid[] = "PC_VAL14_8371";
char pass[] = "728J6[2y";
WiFiClient client_tcp;
char serverAddress[] = "192.168.137.12";
int serverPort = 80;
float last_temp;
void setup() {
//start serial
Serial.begin(9600);
//set potentiometer
pinMode(potarPIN, INPUT);
//setWIFI
setWIFIAndServer();
}
void loop() {
// read POTAR
float wanted_temp = toTemp(analogRead(potarPIN));
if(last_temp!=wanted_temp){
//send data to server
Serial.println(sendAndRead("TEMP="+String(wanted_temp)));
}
last_temp = wanted_temp;
//POTAR END
delay(250);
}
float toTemp(int i){
return float(0.019550342*i+10);
}
void setWIFIAndServer(){
//WIFI
while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
Serial.println("Connexion au Wi-Fi en cours...");
delay(1000);
}
Serial.println("Connecté au Wi-Fi "+String(ssid));
Serial.println("IP : "+String(WiFi.localIP()));
//SERVER TCP
if(!client_tcp.connected()){
if(!client_tcp.connect(serverAddress,serverPort)){
Serial.println("Échec de la connexion au serveur TCP.");
return;
}else{
Serial.print("Success to connect to the TCP Server");
}
}
}
String sendAndRead(String send){
if(!client_tcp.connected()){
if(!client_tcp.connect(serverAddress,serverPort)){
return "Échec de la connexion au serveur TCP.";
}
}
client_tcp.println(send);
bool b = true;
while (b) {
if (client_tcp.available()) {
String request = client_tcp.readStringUntil('\r');
b = false;
return request;
}
}
}