Server HTTP + WebSocket + Serveur TCP pour transmettre la température du thermometre dans ma cuisine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cybergaziniere.ino 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "WiFi.h"
  2. //https://github.com/orgua/OneWireHub or
  3. //https://www.pjrc.com/teensy/td_libs_OneWire.html or
  4. //https://github.com/RobTillaart/DS18B20_RT
  5. #include <OneWire.h>
  6. #include <DS18B20.h>
  7. //https://github.com/avishorp/TM1637
  8. #include <TM1637Display.h>
  9. char* ssid = "Antenne 5G";
  10. char* password = "Un Truc Moins Chiant";
  11. //char* ssid = "Livebox-8DA0";
  12. //char* password = "C3F3EE221002051A31382FFAF7";
  13. char* serverHost = "demisel.space";
  14. int serverPort = 10220;
  15. WiFiClient tcpClient;
  16. bool tcpClientConnected;
  17. #define CLK 18
  18. #define DIO 5
  19. #define ONE_WIRE_BUS 4
  20. OneWire oneWire(ONE_WIRE_BUS);
  21. DS18B20 sensor(&oneWire);
  22. TM1637Display display(CLK, DIO);
  23. void setup() {
  24. WiFi.begin(ssid, password);
  25. // put your setup code here, to run once:
  26. Serial.begin(9600);
  27. sensor.begin();
  28. display.setBrightness(0);
  29. Serial.print("Connecting");
  30. while (WiFi.status() != WL_CONNECTED) {
  31. delay(500);
  32. Serial.print(".");
  33. }
  34. Serial.println();
  35. Serial.print("Connected, IP address: ");
  36. Serial.println(WiFi.localIP());
  37. }
  38. void loop() {
  39. int temp = temperatureTrucs();
  40. //Serial.println(temp);
  41. display.showNumberDecEx(temp, 0x20);
  42. if( !tcpClient.connected() )
  43. {
  44. if(tcpClient.connect(serverHost,serverPort))
  45. {
  46. tcpClientConnected = true;
  47. }else
  48. {
  49. Serial.println("Could not connect to server");
  50. }
  51. }else
  52. {
  53. tcpClient.println(temp);
  54. Serial.println("Connected loop");
  55. }
  56. delay(500);
  57. //;
  58. }
  59. int temperatureTrucs()
  60. {
  61. sensor.requestTemperatures();
  62. while (!sensor.isConversionComplete()); // wait until sensor is ready
  63. return (int) (sensor.getTempC() * 10);
  64. }