├── LICENSE.txt ├── README.txt ├── examples ├── Arduino UNO R4 │ ├── BLE │ │ └── BLE.pde │ ├── WiFi │ │ └── WiFi.pde │ ├── WiFi_cloud │ │ └── WiFi_cloud.pde │ └── WiFi_point │ │ └── WiFi_point.pde ├── Arduino │ ├── Bluetooth_HC05 │ │ └── Bluetooth_HC05.pde │ ├── USB_OTG │ │ └── USB_OTG.pde │ ├── WiFi_ESP8266 │ │ └── WiFi_ESP8266.pde │ ├── WiFi_ESP8266_cloud │ │ └── WiFi_ESP8266_cloud.pde │ └── WiFi_ESP8266_point │ │ └── WiFi_ESP8266_point.pde ├── ESP32 │ ├── BLE │ │ └── BLE.pde │ ├── Bluetooth_classic │ │ └── Bluetooth_classic.pde │ ├── WiFi │ │ └── WiFi.pde │ ├── WiFi_cloud │ │ └── WiFi_cloud.pde │ └── WiFi_point │ │ └── WiFi_point.pde ├── ESP8266 │ ├── WiFi │ │ └── WiFi.pde │ ├── WiFi_cloud │ │ └── WiFi_cloud.pde │ └── WiFi_point │ │ └── WiFi_point.pde ├── Multiple Connection │ ├── ESP32_BLEAndCloud │ │ └── ESP32_BLEAndCloud.pde │ ├── ESP32_BluetoothAndCloud │ │ └── ESP32_BluetoothAndCloud.pde │ ├── ESP_TwoCloudProjects │ │ └── ESP_TwoCloudProjects.pde │ └── ESP_WiFiServerAndCloud │ │ └── ESP_WiFiServerAndCloud.pde ├── NRF │ └── BLE │ │ └── BLE.pde ├── STM32 │ └── USBonChip_OTG │ │ └── USBonChip_OTG.pde ├── Setup Connection │ ├── ESP_WiFiAndCloudSetupUsingAP │ │ └── ESP_WiFiAndCloudSetupUsingAP.pde │ ├── ESP_WiFiSetupUsingAP │ │ └── ESP_WiFiSetupUsingAP.pde │ └── ESP_WiFiSetupUsingBLE │ │ └── ESP_WiFiSetupUsingBLE.pde └── Various │ └── AnyStreamClass │ └── AnyStreamClass.pde ├── keywords.txt ├── library.properties └── src ├── RemoteXY.h ├── RemoteXYApi.h ├── RemoteXYApiData.h ├── RemoteXYCloudServer.h ├── RemoteXYComm.h ├── RemoteXYComm_AT.h ├── RemoteXYComm_ESP8266.h ├── RemoteXYComm_Ethernet.h ├── RemoteXYComm_WiFi.h ├── RemoteXYConnection.h ├── RemoteXYConnectionCloud.h ├── RemoteXYConnectionServer.h ├── RemoteXYConnectionStream.h ├── RemoteXYDebugLog.h ├── RemoteXYFunc.h ├── RemoteXYStream.h ├── RemoteXYStream_AltSoftSerial.h ├── RemoteXYStream_ArduinoBLE.h ├── RemoteXYStream_BLEDevice.h ├── RemoteXYStream_BLEPeripheral.h ├── RemoteXYStream_BluetoothSerial.h ├── RemoteXYStream_HardSerial.h ├── RemoteXYStream_SoftSerial.h ├── RemoteXYStream_Stream.h ├── RemoteXYStream_USBSerial.h ├── RemoteXYThread.h ├── RemoteXYWire.h ├── RemoteXYWireCloud.h └── RemoteXYWireStream.h /README.txt: -------------------------------------------------------------------------------- 1 | Library version: 3.1.14 2 | 3 | This code is the library for Arduino IDE. The library is part of the RemoteXY project. 4 | RemoteXY allows you to control your device using an Android or iOS smartphone. There are Bluetooth, WiFi, Ethernet, USB OTG or Cloud server can be used for connection. 5 | 6 | For more details and make GUI go to website http://remotexy.com/ 7 | 8 | 9 | History: 10 | version 2.3.1 11 | - Support the device access password; 12 | - Support the cloud server as beta test; 13 | - Fixed a bug where the length of variables more than 255; 14 | - Fixed a bug where ESP module reboot and device did not see it; 15 | - Fixed a bug where the connection was filed and the device 16 | did not see it and reconnection is impossible 17 | version 2.3.4 18 | - Fixed a bug where the length of all input variables more than 256; 19 | - Fixed a bug where millis() overflow in 50 days; 20 | - Fixed some bugs; 21 | version 2.3.5 22 | - Fixed some bugs; 23 | version 2.4.1 24 | - support ESP32 WiFi and Bluetooth 25 | version 2.4.2 26 | - Fixed some bugs; 27 | version 2.4.3 28 | - Fixed some bugs; 29 | version 2.4.4 30 | - Fixed ESP32 BLE bugs; 31 | version 3.1.1 32 | - Full update the library: multiple connections, set input variables from board and more; 33 | version 3.1.3 34 | - Multiple connection for cloud, fixed some bugs; 35 | version 3.1.4 36 | - fixed some bugs; 37 | version 3.1.5 38 | - add NRF5XXX and BLEPeripheral.h library as Beta, need define REMOTEXY_MODE__NRFCORE_BLEPERIPHERAL; 39 | version 3.1.6 40 | - fixed some bugs; 41 | version 3.1.7 42 | - add USB CDC Serial for Leonardo, Micro, ..; 43 | version 3.1.8 44 | - fixed some bugs; 45 | version 3.1.9 46 | - added function RemoteXY_delay (ms) as alternative delay (ms); 47 | version 3.1.10 48 | - added suppot for AltSoftSerial.h library; 49 | - support SoftwareSerial.h for ESP8266; 50 | version 3.1.11 51 | - add USB CDC serial for STM32; 52 | version 3.1.12 53 | - fixed some bugs; 54 | - any Stream class can be used for communication: example/RemoteXY/Various/AnyStreamClass.pde 55 | version 3.1.13 56 | - fixed some bugs; 57 | - added support for the arduinoBLE.h library 58 | - added support for the WiFiS3.h library, which uses Arduino UNO R4 WiFi 59 | version 3.1.14 60 | - support ESP32 ver.3.0.x 61 | 62 | -------------------------------------------------------------------------------- /examples/Arduino UNO R4/BLE/BLE.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | #include 26 | #include 27 | 28 | 29 | // RemoteXY configurate 30 | #pragma pack(push, 1) 31 | uint8_t RemoteXY_CONF[] = 32 | { 255,1,0,1,0,27,0,10,13,2, 33 | 1,0,9,9,46,46,6,7,50,50, 34 | 2,31,88,0,65,4,62,16,31,31, 35 | 14,62,35,35 }; 36 | 37 | // this structure defines all the variables and events of your control interface 38 | struct { 39 | 40 | // input variables 41 | uint8_t button_1; // =1 if button pressed, else =0 42 | 43 | // output variables 44 | uint8_t led_1_r; // =0..255 LED Red brightness 45 | 46 | // other variable 47 | uint8_t connect_flag; // =1 if wire connected, else =0 48 | 49 | } RemoteXY; 50 | #pragma pack(pop) 51 | 52 | 53 | 54 | ///////////////////////////////////////////// 55 | // END RemoteXY include // 56 | ///////////////////////////////////////////// 57 | 58 | 59 | CRemoteXY *remotexy; 60 | 61 | void setup() 62 | { 63 | remotexy = new CRemoteXY ( 64 | RemoteXY_CONF_PROGMEM, 65 | &RemoteXY, 66 | new CRemoteXYStream_ArduinoBLE ( 67 | "myRemoteXY" // REMOTEXY_BLUETOOTH_NAME 68 | ) 69 | ); 70 | 71 | 72 | // TODO you setup code 73 | 74 | } 75 | 76 | void loop() 77 | { 78 | remotexy->handler (); 79 | 80 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 81 | else RemoteXY.led_1_r = 0; 82 | 83 | // TODO you loop code 84 | // use the RemoteXY structure for data transfer 85 | // do not call delay() 86 | 87 | 88 | } -------------------------------------------------------------------------------- /examples/Arduino UNO R4/WiFi/WiFi.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | #include 26 | #include 27 | 28 | 29 | // RemoteXY configurate 30 | #pragma pack(push, 1) 31 | uint8_t RemoteXY_CONF[] = 32 | { 255,1,0,1,0,27,0,10,13,2, 33 | 1,0,9,9,46,46,6,7,50,50, 34 | 2,31,88,0,65,4,62,16,31,31, 35 | 14,62,35,35 }; 36 | 37 | // this structure defines all the variables and events of your control interface 38 | struct { 39 | 40 | // input variables 41 | uint8_t button_1; // =1 if button pressed, else =0 42 | 43 | // output variables 44 | uint8_t led_1_r; // =0..255 LED Red brightness 45 | 46 | // other variable 47 | uint8_t connect_flag; // =1 if wire connected, else =0 48 | 49 | } RemoteXY; 50 | #pragma pack(pop) 51 | 52 | 53 | 54 | ///////////////////////////////////////////// 55 | // END RemoteXY include // 56 | ///////////////////////////////////////////// 57 | 58 | 59 | CRemoteXY *remotexy; 60 | 61 | void setup() 62 | { 63 | remotexy = new CRemoteXY ( 64 | RemoteXY_CONF_PROGMEM, 65 | &RemoteXY, 66 | new CRemoteXYConnectionServer ( 67 | new CRemoteXYComm_WiFi ( 68 | "myHomeFiFi", // REMOTEXY_WIFI_SSID 69 | "myPass"), // REMOTEXY_WIFI_PASSWORD 70 | 6377 // REMOTEXY_SERVER_PORT 71 | ) 72 | ); 73 | 74 | 75 | // TODO you setup code 76 | 77 | } 78 | 79 | void loop() 80 | { 81 | remotexy->handler (); 82 | 83 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 84 | else RemoteXY.led_1_r = 0; 85 | 86 | // TODO you loop code 87 | // use the RemoteXY structure for data transfer 88 | // do not call delay() 89 | 90 | 91 | } -------------------------------------------------------------------------------- /examples/Arduino UNO R4/WiFi_cloud/WiFi_cloud.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | #include 26 | #include 27 | 28 | 29 | // RemoteXY configurate 30 | #pragma pack(push, 1) 31 | uint8_t RemoteXY_CONF[] = 32 | { 255,1,0,1,0,27,0,10,13,2, 33 | 1,0,9,9,46,46,6,7,50,50, 34 | 2,31,88,0,65,4,62,16,31,31, 35 | 14,62,35,35 }; 36 | 37 | // this structure defines all the variables and events of your control interface 38 | struct { 39 | 40 | // input variables 41 | uint8_t button_1; // =1 if button pressed, else =0 42 | 43 | // output variables 44 | uint8_t led_1_r; // =0..255 LED Red brightness 45 | 46 | // other variable 47 | uint8_t connect_flag; // =1 if wire connected, else =0 48 | 49 | } RemoteXY; 50 | #pragma pack(pop) 51 | 52 | 53 | 54 | ///////////////////////////////////////////// 55 | // END RemoteXY include // 56 | ///////////////////////////////////////////// 57 | 58 | 59 | CRemoteXY *remotexy; 60 | 61 | void setup() 62 | { 63 | remotexy = new CRemoteXY ( 64 | RemoteXY_CONF_PROGMEM, 65 | &RemoteXY, 66 | new CRemoteXYConnectionCloud ( 67 | new CRemoteXYComm_WiFi ( 68 | "myHomeFiFi", // REMOTEXY_WIFI_SSID 69 | "myPass"), // REMOTEXY_WIFI_PASSWORD 70 | "cloud.remotexy.com", // REMOTEXY_CLOUD_SERVER 71 | 6376, // REMOTEXY_CLOUD_PORT 72 | "xxxxxxxxxxxxxxxxxxxx" // REMOTEXY_CLOUD_TOKEN 73 | ) 74 | ); 75 | 76 | 77 | // TODO you setup code 78 | 79 | } 80 | 81 | void loop() 82 | { 83 | remotexy->handler (); 84 | 85 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 86 | else RemoteXY.led_1_r = 0; 87 | 88 | // TODO you loop code 89 | // use the RemoteXY structure for data transfer 90 | // do not call delay() 91 | 92 | 93 | } -------------------------------------------------------------------------------- /examples/Arduino UNO R4/WiFi_point/WiFi_point.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | #include 26 | #include 27 | 28 | 29 | // RemoteXY configurate 30 | #pragma pack(push, 1) 31 | uint8_t RemoteXY_CONF[] = 32 | { 255,1,0,1,0,27,0,10,13,2, 33 | 1,0,9,9,46,46,6,7,50,50, 34 | 2,31,88,0,65,4,62,16,31,31, 35 | 14,62,35,35 }; 36 | 37 | // this structure defines all the variables and events of your control interface 38 | struct { 39 | 40 | // input variables 41 | uint8_t button_1; // =1 if button pressed, else =0 42 | 43 | // output variables 44 | uint8_t led_1_r; // =0..255 LED Red brightness 45 | 46 | // other variable 47 | uint8_t connect_flag; // =1 if wire connected, else =0 48 | 49 | } RemoteXY; 50 | #pragma pack(pop) 51 | 52 | 53 | 54 | ///////////////////////////////////////////// 55 | // END RemoteXY include // 56 | ///////////////////////////////////////////// 57 | 58 | 59 | CRemoteXY *remotexy; 60 | 61 | void setup() 62 | { 63 | remotexy = new CRemoteXY ( 64 | RemoteXY_CONF_PROGMEM, 65 | &RemoteXY, 66 | new CRemoteXYConnectionServer ( 67 | new CRemoteXYComm_WiFiPoint ( 68 | "myRemoteXY", // REMOTEXY_WIFI_SSID 69 | "12345678"), // REMOTEXY_WIFI_PASSWORD 70 | 6377 // REMOTEXY_SERVER_PORT 71 | ) 72 | ); 73 | 74 | 75 | // TODO you setup code 76 | 77 | } 78 | 79 | void loop() 80 | { 81 | remotexy->handler (); 82 | 83 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 84 | else RemoteXY.led_1_r = 0; 85 | 86 | // TODO you loop code 87 | // use the RemoteXY structure for data transfer 88 | // do not call delay() 89 | 90 | 91 | } -------------------------------------------------------------------------------- /examples/Arduino/Bluetooth_HC05/Bluetooth_HC05.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example using software serial. 3 | 4 | 5 | This source code of graphical user interface 6 | has been generated automatically by RemoteXY editor. 7 | To compile this code using RemoteXY library 3.1.1 or later version 8 | download by link http://remotexy.com/en/library/ 9 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 10 | - for ANDROID 4.5.1 or later version; 11 | - for iOS 1.4.1 or later version; 12 | 13 | This source code is free software; you can redistribute it and/or 14 | modify it under the terms of the GNU Lesser General Public 15 | License as published by the Free Software Foundation; either 16 | version 2.1 of the License, or (at your option) any later version. 17 | */ 18 | 19 | ////////////////////////////////////////////// 20 | // RemoteXY include library // 21 | ////////////////////////////////////////////// 22 | 23 | // RemoteXY select connection mode and include library 24 | //#define REMOTEXY__DEBUGLOG 25 | 26 | #include 27 | #include 28 | 29 | 30 | // RemoteXY configurate 31 | #pragma pack(push, 1) 32 | uint8_t RemoteXY_CONF[] = 33 | { 255,1,0,1,0,27,0,10,13,2, 34 | 1,0,9,9,46,46,6,7,50,50, 35 | 2,31,88,0,65,4,62,16,31,31, 36 | 14,62,35,35 }; 37 | 38 | // this structure defines all the variables and events of your control interface 39 | struct { 40 | 41 | // input variables 42 | uint8_t button_1; // =1 if button pressed, else =0 43 | 44 | // output variables 45 | uint8_t led_1_r; // =0..255 LED Red brightness 46 | 47 | // other variable 48 | uint8_t connect_flag; // =1 if wire connected, else =0 49 | 50 | } RemoteXY; 51 | #pragma pack(pop) 52 | 53 | 54 | 55 | ///////////////////////////////////////////// 56 | // END RemoteXY include // 57 | ///////////////////////////////////////////// 58 | 59 | 60 | CRemoteXY *remotexy; 61 | 62 | void setup() 63 | { 64 | 65 | remotexy = new CRemoteXY ( 66 | RemoteXY_CONF_PROGMEM, 67 | &RemoteXY, 68 | new CRemoteXYStream_SoftSerial ( 69 | 2, // REMOTEXY_SERIAL_RX 70 | 3, // REMOTEXY_SERIAL_TX, 71 | 9600 // REMOTEXY_SERIAL_SPEED 72 | ) 73 | ); 74 | 75 | 76 | // TODO you setup code 77 | 78 | } 79 | 80 | void loop() 81 | { 82 | remotexy->handler (); 83 | 84 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 85 | else RemoteXY.led_1_r = 0; 86 | 87 | // TODO you loop code 88 | // use the RemoteXY structure for data transfer 89 | // do not call delay() 90 | 91 | 92 | } -------------------------------------------------------------------------------- /examples/Arduino/USB_OTG/USB_OTG.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Example of USB connection to USB OTG phone. 3 | The on board USB-UART converter is used. 4 | 5 | This source code of graphical user interface 6 | has been generated automatically by RemoteXY editor. 7 | To compile this code using RemoteXY library 3.1.1 or later version 8 | download by link http://remotexy.com/en/library/ 9 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 10 | - for ANDROID 4.5.1 or later version; 11 | - for iOS 1.4.1 or later version; 12 | 13 | This source code is free software; you can redistribute it and/or 14 | modify it under the terms of the GNU Lesser General Public 15 | License as published by the Free Software Foundation; either 16 | version 2.1 of the License, or (at your option) any later version. 17 | */ 18 | 19 | ////////////////////////////////////////////// 20 | // RemoteXY include library // 21 | ////////////////////////////////////////////// 22 | 23 | // RemoteXY select connection mode and include library 24 | //#define REMOTEXY__DEBUGLOG 25 | 26 | #include 27 | 28 | 29 | // RemoteXY configurate 30 | #pragma pack(push, 1) 31 | uint8_t RemoteXY_CONF[] = 32 | { 255,1,0,1,0,27,0,10,13,2, 33 | 1,0,9,9,46,46,6,7,50,50, 34 | 2,31,88,0,65,4,62,16,31,31, 35 | 14,62,35,35 }; 36 | 37 | // this structure defines all the variables and events of your control interface 38 | struct { 39 | 40 | // input variables 41 | uint8_t button_1; // =1 if button pressed, else =0 42 | 43 | // output variables 44 | uint8_t led_1_r; // =0..255 LED Red brightness 45 | 46 | // other variable 47 | uint8_t connect_flag; // =1 if wire connected, else =0 48 | 49 | } RemoteXY; 50 | #pragma pack(pop) 51 | 52 | 53 | 54 | ///////////////////////////////////////////// 55 | // END RemoteXY include // 56 | ///////////////////////////////////////////// 57 | 58 | 59 | CRemoteXY *remotexy; 60 | 61 | void setup() 62 | { 63 | 64 | remotexy = new CRemoteXY ( 65 | RemoteXY_CONF_PROGMEM, 66 | &RemoteXY, 67 | new CRemoteXYStream_HardSerial ( 68 | &Serial, 69 | 115200 // REMOTEXY_SERIAL_SPEED 70 | ) 71 | ); 72 | 73 | 74 | // TODO you setup code 75 | 76 | } 77 | 78 | void loop() 79 | { 80 | remotexy->handler (); 81 | 82 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 83 | else RemoteXY.led_1_r = 0; 84 | 85 | // TODO you loop code 86 | // use the RemoteXY structure for data transfer 87 | // do not call delay() 88 | 89 | 90 | } -------------------------------------------------------------------------------- /examples/Arduino/WiFi_ESP8266/WiFi_ESP8266.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example for Arduino and external ESP8266 on HardwareSerial 3 | You must disconnect ESP8266 from pins when loading the program 4 | 5 | 6 | This source code of graphical user interface 7 | has been generated automatically by RemoteXY editor. 8 | To compile this code using RemoteXY library 3.1.1 or later version 9 | download by link http://remotexy.com/en/library/ 10 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 11 | - for ANDROID 4.5.1 or later version; 12 | - for iOS 1.4.1 or later version; 13 | 14 | This source code is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU Lesser General Public 16 | License as published by the Free Software Foundation; either 17 | version 2.1 of the License, or (at your option) any later version. 18 | */ 19 | 20 | ////////////////////////////////////////////// 21 | // RemoteXY include library // 22 | ////////////////////////////////////////////// 23 | 24 | // RemoteXY select connection mode and include library 25 | //#define REMOTEXY__DEBUGLOG 26 | 27 | #include 28 | 29 | 30 | // RemoteXY configurate 31 | #pragma pack(push, 1) 32 | uint8_t const PROGMEM RemoteXY_CONF_PROGMEM[] = 33 | { 255,1,0,1,0,27,0,10,13,2, 34 | 1,0,9,9,46,46,6,7,50,50, 35 | 2,31,88,0,65,4,62,16,31,31, 36 | 14,62,35,35 }; 37 | 38 | // this structure defines all the variables and events of your control interface 39 | struct { 40 | 41 | // input variables 42 | uint8_t button_1; // =1 if button pressed, else =0 43 | 44 | // output variables 45 | uint8_t led_1_r; // =0..255 LED Red brightness 46 | 47 | // other variable 48 | uint8_t connect_flag; // =1 if wire connected, else =0 49 | 50 | } RemoteXY; 51 | #pragma pack(pop) 52 | 53 | 54 | 55 | ///////////////////////////////////////////// 56 | // END RemoteXY include // 57 | ///////////////////////////////////////////// 58 | 59 | 60 | CRemoteXY *remotexy; 61 | 62 | void setup() 63 | { 64 | remotexy = new CRemoteXY ( 65 | RemoteXY_CONF_PROGMEM, 66 | &RemoteXY, 67 | new CRemoteXYConnectionServer ( 68 | new CRemoteXYComm_ESP8266 ( 69 | new CRemoteXYStream_HardSerial ( 70 | &Serial, // use Serial1 (Serial2, Serial3) for Arduino Mega board 71 | 115200 72 | ), 73 | "myHomeFiFi", // REMOTEXY_WIFI_SSID 74 | "12345678"), // REMOTEXY_WIFI_PASSWORD 75 | 6377 // REMOTEXY_SERVER_PORT 76 | ) 77 | ); 78 | 79 | 80 | // TODO you setup code 81 | 82 | } 83 | 84 | void loop() 85 | { 86 | remotexy->handler (); 87 | 88 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 89 | else RemoteXY.led_1_r = 0; 90 | 91 | // TODO you loop code 92 | // use the RemoteXY structure for data transfer 93 | // do not call delay() 94 | 95 | 96 | } 97 | -------------------------------------------------------------------------------- /examples/Arduino/WiFi_ESP8266_cloud/WiFi_ESP8266_cloud.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example for Arduino and external ESP8266 on HardwareSerial 3 | You must disconnect ESP8266 from pins when loading the program 4 | 5 | 6 | This source code of graphical user interface 7 | has been generated automatically by RemoteXY editor. 8 | To compile this code using RemoteXY library 3.1.1 or later version 9 | download by link http://remotexy.com/en/library/ 10 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 11 | - for ANDROID 4.5.1 or later version; 12 | - for iOS 1.4.1 or later version; 13 | 14 | This source code is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU Lesser General Public 16 | License as published by the Free Software Foundation; either 17 | version 2.1 of the License, or (at your option) any later version. 18 | */ 19 | 20 | ////////////////////////////////////////////// 21 | // RemoteXY include library // 22 | ////////////////////////////////////////////// 23 | 24 | // RemoteXY select connection mode and include library 25 | //#define REMOTEXY__DEBUGLOG 26 | 27 | #include 28 | 29 | 30 | // RemoteXY configurate 31 | #pragma pack(push, 1) 32 | uint8_t const PROGMEM RemoteXY_CONF_PROGMEM[] = 33 | { 255,1,0,1,0,27,0,10,13,2, 34 | 1,0,9,9,46,46,6,7,50,50, 35 | 2,31,88,0,65,4,62,16,31,31, 36 | 14,62,35,35 }; 37 | 38 | // this structure defines all the variables and events of your control interface 39 | struct { 40 | 41 | // input variables 42 | uint8_t button_1; // =1 if button pressed, else =0 43 | 44 | // output variables 45 | uint8_t led_1_r; // =0..255 LED Red brightness 46 | 47 | // other variable 48 | uint8_t connect_flag; // =1 if wire connected, else =0 49 | 50 | } RemoteXY; 51 | #pragma pack(pop) 52 | 53 | 54 | 55 | ///////////////////////////////////////////// 56 | // END RemoteXY include // 57 | ///////////////////////////////////////////// 58 | 59 | 60 | CRemoteXY *remotexy; 61 | 62 | void setup() 63 | { 64 | remotexy = new CRemoteXY ( 65 | RemoteXY_CONF_PROGMEM, 66 | &RemoteXY, 67 | new CRemoteXYConnectionCloud ( 68 | new CRemoteXYComm_ESP8266 ( 69 | new CRemoteXYStream_HardSerial ( 70 | &Serial, // use Serial1 (Serial2, Serial3) for Arduino Mega board 71 | 115200 72 | ), 73 | "myHomeFiFi", // REMOTEXY_WIFI_SSID 74 | "myHomePass"), // REMOTEXY_WIFI_PASSWORD 75 | "cloud.remotexy.com", // REMOTEXY_CLOUD_SERVER 76 | 6376, // REMOTEXY_CLOUD_PORT 77 | "xxxxxxxxxxxxxxxxxxxx" // REMOTEXY_CLOUD_TOKEN 78 | ) 79 | ); 80 | 81 | 82 | // TODO you setup code 83 | 84 | } 85 | 86 | void loop() 87 | { 88 | remotexy->handler (); 89 | 90 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 91 | else RemoteXY.led_1_r = 0; 92 | 93 | // TODO you loop code 94 | // use the RemoteXY structure for data transfer 95 | // do not call delay() 96 | 97 | 98 | } 99 | -------------------------------------------------------------------------------- /examples/Arduino/WiFi_ESP8266_point/WiFi_ESP8266_point.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example for Arduino and external ESP8266 as WiFi point on HardwareSerial 3 | You must disconnect ESP8266 from pins when loading the program 4 | 5 | 6 | This source code of graphical user interface 7 | has been generated automatically by RemoteXY editor. 8 | To compile this code using RemoteXY library 3.1.1 or later version 9 | download by link http://remotexy.com/en/library/ 10 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 11 | - for ANDROID 4.5.1 or later version; 12 | - for iOS 1.4.1 or later version; 13 | 14 | This source code is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU Lesser General Public 16 | License as published by the Free Software Foundation; either 17 | version 2.1 of the License, or (at your option) any later version. 18 | */ 19 | 20 | ////////////////////////////////////////////// 21 | // RemoteXY include library // 22 | ////////////////////////////////////////////// 23 | 24 | // RemoteXY select connection mode and include library 25 | //#define REMOTEXY__DEBUGLOG 26 | 27 | #include 28 | 29 | 30 | // RemoteXY configurate 31 | #pragma pack(push, 1) 32 | uint8_t const PROGMEM RemoteXY_CONF_PROGMEM[] = 33 | { 255,1,0,1,0,27,0,10,13,2, 34 | 1,0,9,9,46,46,6,7,50,50, 35 | 2,31,88,0,65,4,62,16,31,31, 36 | 14,62,35,35 }; 37 | 38 | // this structure defines all the variables and events of your control interface 39 | struct { 40 | 41 | // input variables 42 | uint8_t button_1; // =1 if button pressed, else =0 43 | 44 | // output variables 45 | uint8_t led_1_r; // =0..255 LED Red brightness 46 | 47 | // other variable 48 | uint8_t connect_flag; // =1 if wire connected, else =0 49 | 50 | } RemoteXY; 51 | #pragma pack(pop) 52 | 53 | 54 | 55 | ///////////////////////////////////////////// 56 | // END RemoteXY include // 57 | ///////////////////////////////////////////// 58 | 59 | 60 | CRemoteXY *remotexy; 61 | 62 | void setup() 63 | { 64 | remotexy = new CRemoteXY ( 65 | RemoteXY_CONF_PROGMEM, 66 | &RemoteXY, 67 | new CRemoteXYConnectionServer ( 68 | new CRemoteXYComm_ESP8266Point ( 69 | new CRemoteXYStream_HardSerial ( 70 | &Serial, // use Serial1 (Serial2, Serial3) for Arduino Mega board 71 | 115200 72 | ), 73 | "myRemoteXY", // REMOTEXY_WIFI_SSID 74 | "12345678"), // REMOTEXY_WIFI_PASSWORD 75 | 6377 // REMOTEXY_SERVER_PORT 76 | ) 77 | ); 78 | 79 | 80 | // TODO you setup code 81 | 82 | } 83 | 84 | void loop() 85 | { 86 | remotexy->handler (); 87 | 88 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 89 | else RemoteXY.led_1_r = 0; 90 | 91 | // TODO you loop code 92 | // use the RemoteXY structure for data transfer 93 | // do not call delay() 94 | 95 | 96 | } 97 | -------------------------------------------------------------------------------- /examples/ESP32/BLE/BLE.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | #include "BLEDevice.h" 26 | #include 27 | 28 | 29 | // RemoteXY configurate 30 | #pragma pack(push, 1) 31 | uint8_t RemoteXY_CONF[] = 32 | { 255,1,0,1,0,27,0,10,13,2, 33 | 1,0,9,9,46,46,6,7,50,50, 34 | 2,31,88,0,65,4,62,16,31,31, 35 | 14,62,35,35 }; 36 | 37 | // this structure defines all the variables and events of your control interface 38 | struct { 39 | 40 | // input variables 41 | uint8_t button_1; // =1 if button pressed, else =0 42 | 43 | // output variables 44 | uint8_t led_1_r; // =0..255 LED Red brightness 45 | 46 | // other variable 47 | uint8_t connect_flag; // =1 if wire connected, else =0 48 | 49 | } RemoteXY; 50 | #pragma pack(pop) 51 | 52 | 53 | 54 | ///////////////////////////////////////////// 55 | // END RemoteXY include // 56 | ///////////////////////////////////////////// 57 | 58 | 59 | CRemoteXY *remotexy; 60 | 61 | void setup() 62 | { 63 | remotexy = new CRemoteXY ( 64 | RemoteXY_CONF_PROGMEM, 65 | &RemoteXY, 66 | new CRemoteXYStream_BLEDevice ( 67 | "myRemoteXY" // REMOTEXY_BLUETOOTH_NAME 68 | ) 69 | ); 70 | 71 | 72 | // TODO you setup code 73 | 74 | } 75 | 76 | void loop() 77 | { 78 | remotexy->handler (); 79 | 80 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 81 | else RemoteXY.led_1_r = 0; 82 | 83 | // TODO you loop code 84 | // use the RemoteXY structure for data transfer 85 | // do not call delay() 86 | 87 | 88 | } -------------------------------------------------------------------------------- /examples/ESP32/Bluetooth_classic/Bluetooth_classic.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | #include "BluetoothSerial.h" 26 | #include 27 | 28 | 29 | // RemoteXY configurate 30 | #pragma pack(push, 1) 31 | uint8_t RemoteXY_CONF[] = 32 | { 255,1,0,1,0,27,0,10,13,2, 33 | 1,0,9,9,46,46,6,7,50,50, 34 | 2,31,88,0,65,4,62,16,31,31, 35 | 14,62,35,35 }; 36 | 37 | // this structure defines all the variables and events of your control interface 38 | struct { 39 | 40 | // input variables 41 | uint8_t button_1; // =1 if button pressed, else =0 42 | 43 | // output variables 44 | uint8_t led_1_r; // =0..255 LED Red brightness 45 | 46 | // other variable 47 | uint8_t connect_flag; // =1 if wire connected, else =0 48 | 49 | } RemoteXY; 50 | #pragma pack(pop) 51 | 52 | 53 | 54 | ///////////////////////////////////////////// 55 | // END RemoteXY include // 56 | ///////////////////////////////////////////// 57 | 58 | 59 | CRemoteXY *remotexy; 60 | 61 | void setup() 62 | { 63 | remotexy = new CRemoteXY ( 64 | RemoteXY_CONF_PROGMEM, 65 | &RemoteXY, 66 | new CRemoteXYStream_BluetoothSerial ( 67 | "myRemoteXY" // REMOTEXY_BLUETOOTH_NAME 68 | ) 69 | ); 70 | 71 | 72 | // TODO you setup code 73 | 74 | } 75 | 76 | void loop() 77 | { 78 | remotexy->handler (); 79 | 80 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 81 | else RemoteXY.led_1_r = 0; 82 | 83 | // TODO you loop code 84 | // use the RemoteXY structure for data transfer 85 | // do not call delay() 86 | 87 | 88 | } -------------------------------------------------------------------------------- /examples/ESP32/WiFi/WiFi.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | #include 26 | #include 27 | 28 | 29 | // RemoteXY configurate 30 | #pragma pack(push, 1) 31 | uint8_t RemoteXY_CONF[] = 32 | { 255,1,0,1,0,27,0,10,13,2, 33 | 1,0,9,9,46,46,6,7,50,50, 34 | 2,31,88,0,65,4,62,16,31,31, 35 | 14,62,35,35 }; 36 | 37 | // this structure defines all the variables and events of your control interface 38 | struct { 39 | 40 | // input variables 41 | uint8_t button_1; // =1 if button pressed, else =0 42 | 43 | // output variables 44 | uint8_t led_1_r; // =0..255 LED Red brightness 45 | 46 | // other variable 47 | uint8_t connect_flag; // =1 if wire connected, else =0 48 | 49 | } RemoteXY; 50 | #pragma pack(pop) 51 | 52 | 53 | 54 | ///////////////////////////////////////////// 55 | // END RemoteXY include // 56 | ///////////////////////////////////////////// 57 | 58 | 59 | CRemoteXY *remotexy; 60 | 61 | void setup() 62 | { 63 | remotexy = new CRemoteXY ( 64 | RemoteXY_CONF_PROGMEM, 65 | &RemoteXY, 66 | new CRemoteXYConnectionServer ( 67 | new CRemoteXYComm_WiFi ( 68 | "myHomeFiFi", // REMOTEXY_WIFI_SSID 69 | "myPass"), // REMOTEXY_WIFI_PASSWORD 70 | 6377 // REMOTEXY_SERVER_PORT 71 | ) 72 | ); 73 | 74 | 75 | // TODO you setup code 76 | 77 | } 78 | 79 | void loop() 80 | { 81 | remotexy->handler (); 82 | 83 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 84 | else RemoteXY.led_1_r = 0; 85 | 86 | // TODO you loop code 87 | // use the RemoteXY structure for data transfer 88 | // do not call delay() 89 | 90 | 91 | } -------------------------------------------------------------------------------- /examples/ESP32/WiFi_cloud/WiFi_cloud.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | #include 26 | #include 27 | 28 | 29 | // RemoteXY configurate 30 | #pragma pack(push, 1) 31 | uint8_t RemoteXY_CONF[] = 32 | { 255,1,0,1,0,27,0,10,13,2, 33 | 1,0,9,9,46,46,6,7,50,50, 34 | 2,31,88,0,65,4,62,16,31,31, 35 | 14,62,35,35 }; 36 | 37 | // this structure defines all the variables and events of your control interface 38 | struct { 39 | 40 | // input variables 41 | uint8_t button_1; // =1 if button pressed, else =0 42 | 43 | // output variables 44 | uint8_t led_1_r; // =0..255 LED Red brightness 45 | 46 | // other variable 47 | uint8_t connect_flag; // =1 if wire connected, else =0 48 | 49 | } RemoteXY; 50 | #pragma pack(pop) 51 | 52 | 53 | 54 | ///////////////////////////////////////////// 55 | // END RemoteXY include // 56 | ///////////////////////////////////////////// 57 | 58 | 59 | CRemoteXY *remotexy; 60 | 61 | void setup() 62 | { 63 | remotexy = new CRemoteXY ( 64 | RemoteXY_CONF_PROGMEM, 65 | &RemoteXY, 66 | new CRemoteXYConnectionCloud ( 67 | new CRemoteXYComm_WiFi ( 68 | "myHomeFiFi", // REMOTEXY_WIFI_SSID 69 | "myPass"), // REMOTEXY_WIFI_PASSWORD 70 | "cloud.remotexy.com", // REMOTEXY_CLOUD_SERVER 71 | 6376, // REMOTEXY_CLOUD_PORT 72 | "xxxxxxxxxxxxxxxxxxxx" // REMOTEXY_CLOUD_TOKEN 73 | ) 74 | ); 75 | 76 | 77 | // TODO you setup code 78 | 79 | } 80 | 81 | void loop() 82 | { 83 | remotexy->handler (); 84 | 85 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 86 | else RemoteXY.led_1_r = 0; 87 | 88 | // TODO you loop code 89 | // use the RemoteXY structure for data transfer 90 | // do not call delay() 91 | 92 | 93 | } -------------------------------------------------------------------------------- /examples/ESP32/WiFi_point/WiFi_point.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | #include 26 | #include 27 | 28 | 29 | // RemoteXY configurate 30 | #pragma pack(push, 1) 31 | uint8_t RemoteXY_CONF[] = 32 | { 255,1,0,1,0,27,0,10,13,2, 33 | 1,0,9,9,46,46,6,7,50,50, 34 | 2,31,88,0,65,4,62,16,31,31, 35 | 14,62,35,35 }; 36 | 37 | // this structure defines all the variables and events of your control interface 38 | struct { 39 | 40 | // input variables 41 | uint8_t button_1; // =1 if button pressed, else =0 42 | 43 | // output variables 44 | uint8_t led_1_r; // =0..255 LED Red brightness 45 | 46 | // other variable 47 | uint8_t connect_flag; // =1 if wire connected, else =0 48 | 49 | } RemoteXY; 50 | #pragma pack(pop) 51 | 52 | 53 | 54 | ///////////////////////////////////////////// 55 | // END RemoteXY include // 56 | ///////////////////////////////////////////// 57 | 58 | 59 | CRemoteXY *remotexy; 60 | 61 | void setup() 62 | { 63 | remotexy = new CRemoteXY ( 64 | RemoteXY_CONF_PROGMEM, 65 | &RemoteXY, 66 | new CRemoteXYConnectionServer ( 67 | new CRemoteXYComm_WiFiPoint ( 68 | "myRemoteXY", // REMOTEXY_WIFI_SSID 69 | "12345678"), // REMOTEXY_WIFI_PASSWORD 70 | 6377 // REMOTEXY_SERVER_PORT 71 | ) 72 | ); 73 | 74 | 75 | // TODO you setup code 76 | 77 | } 78 | 79 | void loop() 80 | { 81 | remotexy->handler (); 82 | 83 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 84 | else RemoteXY.led_1_r = 0; 85 | 86 | // TODO you loop code 87 | // use the RemoteXY structure for data transfer 88 | // do not call delay() 89 | 90 | 91 | } -------------------------------------------------------------------------------- /examples/ESP8266/WiFi/WiFi.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | 26 | #include 27 | #include 28 | 29 | 30 | // RemoteXY configurate 31 | #pragma pack(push, 1) 32 | uint8_t RemoteXY_CONF[] = 33 | { 255,1,0,1,0,27,0,10,13,2, 34 | 1,0,9,9,46,46,6,7,50,50, 35 | 2,31,88,0,65,4,62,16,31,31, 36 | 14,62,35,35 }; 37 | 38 | // this structure defines all the variables and events of your control interface 39 | struct { 40 | 41 | // input variables 42 | uint8_t button_1; // =1 if button pressed, else =0 43 | 44 | // output variables 45 | uint8_t led_1_r; // =0..255 LED Red brightness 46 | 47 | // other variable 48 | uint8_t connect_flag; // =1 if wire connected, else =0 49 | 50 | } RemoteXY; 51 | #pragma pack(pop) 52 | 53 | 54 | 55 | ///////////////////////////////////////////// 56 | // END RemoteXY include // 57 | ///////////////////////////////////////////// 58 | 59 | 60 | CRemoteXY *remotexy; 61 | 62 | void setup() 63 | { 64 | remotexy = new CRemoteXY ( 65 | RemoteXY_CONF_PROGMEM, 66 | &RemoteXY, 67 | new CRemoteXYConnectionServer ( 68 | new CRemoteXYComm_WiFi ( 69 | "myHomeFiFi", // REMOTEXY_WIFI_SSID 70 | "myPass"), // REMOTEXY_WIFI_PASSWORD 71 | 6377 // REMOTEXY_SERVER_PORT 72 | ) 73 | ); 74 | 75 | 76 | // TODO you setup code 77 | 78 | } 79 | 80 | void loop() 81 | { 82 | remotexy->handler (); 83 | 84 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 85 | else RemoteXY.led_1_r = 0; 86 | 87 | // TODO you loop code 88 | // use the RemoteXY structure for data transfer 89 | // do not call delay() 90 | 91 | 92 | } -------------------------------------------------------------------------------- /examples/ESP8266/WiFi_cloud/WiFi_cloud.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | #include 26 | #include 27 | 28 | 29 | // RemoteXY configurate 30 | #pragma pack(push, 1) 31 | uint8_t RemoteXY_CONF[] = 32 | { 255,1,0,1,0,27,0,10,13,2, 33 | 1,0,9,9,46,46,6,7,50,50, 34 | 2,31,88,0,65,4,62,16,31,31, 35 | 14,62,35,35 }; 36 | 37 | // this structure defines all the variables and events of your control interface 38 | struct { 39 | 40 | // input variables 41 | uint8_t button_1; // =1 if button pressed, else =0 42 | 43 | // output variables 44 | uint8_t led_1_r; // =0..255 LED Red brightness 45 | 46 | // other variable 47 | uint8_t connect_flag; // =1 if wire connected, else =0 48 | 49 | } RemoteXY; 50 | #pragma pack(pop) 51 | 52 | 53 | 54 | ///////////////////////////////////////////// 55 | // END RemoteXY include // 56 | ///////////////////////////////////////////// 57 | 58 | 59 | CRemoteXY *remotexy; 60 | 61 | void setup() 62 | { 63 | remotexy = new CRemoteXY ( 64 | RemoteXY_CONF_PROGMEM, 65 | &RemoteXY, 66 | new CRemoteXYConnectionCloud ( 67 | new CRemoteXYComm_WiFi ( 68 | "myHomeFiFi", // REMOTEXY_WIFI_SSID 69 | "myPass"), // REMOTEXY_WIFI_PASSWORD 70 | "cloud.remotexy.com", // REMOTEXY_CLOUD_SERVER 71 | 6376, // REMOTEXY_CLOUD_PORT 72 | "xxxxxxxxxxxxxxxxxxxx" // REMOTEXY_CLOUD_TOKEN 73 | ) 74 | ); 75 | 76 | 77 | // TODO you setup code 78 | 79 | } 80 | 81 | void loop() 82 | { 83 | remotexy->handler (); 84 | 85 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 86 | else RemoteXY.led_1_r = 0; 87 | 88 | // TODO you loop code 89 | // use the RemoteXY structure for data transfer 90 | // do not call delay() 91 | 92 | 93 | } -------------------------------------------------------------------------------- /examples/ESP8266/WiFi_point/WiFi_point.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | 26 | #include 27 | #include 28 | 29 | 30 | // RemoteXY configurate 31 | #pragma pack(push, 1) 32 | uint8_t RemoteXY_CONF[] = 33 | { 255,1,0,1,0,27,0,10,13,2, 34 | 1,0,9,9,46,46,6,7,50,50, 35 | 2,31,88,0,65,4,62,16,31,31, 36 | 14,62,35,35 }; 37 | 38 | // this structure defines all the variables and events of your control interface 39 | struct { 40 | 41 | // input variables 42 | uint8_t button_1; // =1 if button pressed, else =0 43 | 44 | // output variables 45 | uint8_t led_1_r; // =0..255 LED Red brightness 46 | 47 | // other variable 48 | uint8_t connect_flag; // =1 if wire connected, else =0 49 | 50 | } RemoteXY; 51 | #pragma pack(pop) 52 | 53 | 54 | 55 | ///////////////////////////////////////////// 56 | // END RemoteXY include // 57 | ///////////////////////////////////////////// 58 | 59 | 60 | CRemoteXY *remotexy; 61 | 62 | void setup() 63 | { 64 | remotexy = new CRemoteXY ( 65 | RemoteXY_CONF_PROGMEM, 66 | &RemoteXY, 67 | new CRemoteXYConnectionServer ( 68 | new CRemoteXYComm_WiFiPoint ( 69 | "myRemoteXY", // REMOTEXY_WIFI_SSID 70 | "12345678"), // REMOTEXY_WIFI_PASSWORD 71 | 6377 // REMOTEXY_SERVER_PORT 72 | ) 73 | ); 74 | 75 | 76 | // TODO you setup code 77 | 78 | } 79 | 80 | void loop() 81 | { 82 | remotexy->handler (); 83 | 84 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 85 | else RemoteXY.led_1_r = 0; 86 | 87 | // TODO you loop code 88 | // use the RemoteXY structure for data transfer 89 | // do not call delay() 90 | 91 | 92 | } -------------------------------------------------------------------------------- /examples/Multiple Connection/ESP32_BLEAndCloud/ESP32_BLEAndCloud.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Example: using BLE and cloud connections together on ESP32 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | 26 | #include 27 | #include "BLEDevice.h" 28 | 29 | #include 30 | 31 | 32 | // RemoteXY configurate 33 | #pragma pack(push, 1) 34 | uint8_t RemoteXY_CONF[] = 35 | { 255,1,0,1,0,27,0,10,13,2, 36 | 1,0,9,9,46,46,6,7,50,50, 37 | 2,31,88,0,65,4,62,16,31,31, 38 | 14,62,35,35 }; 39 | 40 | // this structure defines all the variables and events of your control interface 41 | struct { 42 | 43 | // input variables 44 | uint8_t button_1; // =1 if button pressed, else =0 45 | 46 | // output variables 47 | uint8_t led_1_r; // =0..255 LED Red brightness 48 | 49 | // other variable 50 | uint8_t connect_flag; // =1 if wire connected, else =0 51 | 52 | } RemoteXY; 53 | #pragma pack(pop) 54 | 55 | 56 | 57 | ///////////////////////////////////////////// 58 | // END RemoteXY include // 59 | ///////////////////////////////////////////// 60 | 61 | 62 | CRemoteXY *remotexy; 63 | 64 | void setup() 65 | { 66 | 67 | CRemoteXYComm_WiFi * wifi = new CRemoteXYComm_WiFi ( 68 | "myHomeFiFi", // REMOTEXY_WIFI_SSID 69 | "myPass" // REMOTEXY_WIFI_PASSWORD 70 | ); 71 | 72 | remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY); 73 | 74 | remotexy->addConnection (new CRemoteXYStream_BLEDevice ( 75 | "REMOTEXY" // REMOTEXY_BLUETOOTH_NAME 76 | )); 77 | 78 | remotexy->addConnection (new CRemoteXYConnectionCloud ( wifi, 79 | "cloud.remotexy.com", // REMOTEXY_CLOUD_SERVER 80 | 6376, // REMOTEXY_CLOUD_PORT 81 | "xxxxxxxxxxxxxxxxxxxxxxxx" // REMOTEXY_CLOUD_TOKEN 82 | )); 83 | 84 | 85 | 86 | // TODO you setup code 87 | 88 | } 89 | 90 | void loop() 91 | { 92 | remotexy->handler (); 93 | 94 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 95 | else RemoteXY.led_1_r = 0; 96 | 97 | // TODO you loop code 98 | // use the RemoteXY structure for data transfer 99 | // do not call delay() 100 | 101 | 102 | } 103 | -------------------------------------------------------------------------------- /examples/Multiple Connection/ESP32_BluetoothAndCloud/ESP32_BluetoothAndCloud.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Example: using Bluetooth classic and cloud connections together on ESP32 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | 26 | #include 27 | #include "BluetoothSerial.h" 28 | 29 | #include 30 | 31 | 32 | // RemoteXY configurate 33 | #pragma pack(push, 1) 34 | uint8_t RemoteXY_CONF[] = 35 | { 255,1,0,1,0,27,0,10,13,2, 36 | 1,0,9,9,46,46,6,7,50,50, 37 | 2,31,88,0,65,4,62,16,31,31, 38 | 14,62,35,35 }; 39 | 40 | // this structure defines all the variables and events of your control interface 41 | struct { 42 | 43 | // input variables 44 | uint8_t button_1; // =1 if button pressed, else =0 45 | 46 | // output variables 47 | uint8_t led_1_r; // =0..255 LED Red brightness 48 | 49 | // other variable 50 | uint8_t connect_flag; // =1 if wire connected, else =0 51 | 52 | } RemoteXY; 53 | #pragma pack(pop) 54 | 55 | 56 | 57 | ///////////////////////////////////////////// 58 | // END RemoteXY include // 59 | ///////////////////////////////////////////// 60 | 61 | 62 | CRemoteXY *remotexy; 63 | 64 | void setup() 65 | { 66 | 67 | CRemoteXYComm_WiFi * wifi = new CRemoteXYComm_WiFi ( 68 | "myHomeFiFi", // REMOTEXY_WIFI_SSID 69 | "myPass" // REMOTEXY_WIFI_PASSWORD 70 | ); 71 | 72 | remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY); 73 | 74 | remotexy->addConnection (new CRemoteXYStream_BluetoothSerial ( 75 | "REMOTEXY" // REMOTEXY_BLUETOOTH_NAME 76 | )); 77 | 78 | remotexy->addConnection (new CRemoteXYConnectionCloud ( wifi, 79 | "cloud.remotexy.com", // REMOTEXY_CLOUD_SERVER 80 | 6376, // REMOTEXY_CLOUD_PORT 81 | "xxxxxxxxxxxxxxxxxxxxxxxx" // REMOTEXY_CLOUD_TOKEN 82 | )); 83 | 84 | 85 | 86 | // TODO you setup code 87 | 88 | } 89 | 90 | void loop() 91 | { 92 | remotexy->handler (); 93 | 94 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 95 | else RemoteXY.led_1_r = 0; 96 | 97 | // TODO you loop code 98 | // use the RemoteXY structure for data transfer 99 | // do not call delay() 100 | 101 | 102 | } 103 | -------------------------------------------------------------------------------- /examples/Multiple Connection/ESP_TwoCloudProjects/ESP_TwoCloudProjects.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Example: two cloud projects on one board, two tokens are used 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | #define REMOTEXY__DEBUGLOG 24 | 25 | #if defined (ESP8266) 26 | #include 27 | #elif defined (ESP32) 28 | #include 29 | #endif 30 | 31 | #include 32 | 33 | 34 | // RemoteXY configurate 35 | 36 | ///////////////////////////////////////////////////////////// 37 | // First 38 | 39 | #pragma pack(push, 1) 40 | uint8_t const PROGMEM RemoteXY_CONF_PROGMEM_1[] = 41 | { 255,1,0,1,0,27,0,10,13,2, 42 | 1,0,9,9,46,46,6,7,50,50, 43 | 2,31,88,0,65,4,62,16,31,31, 44 | 14,62,35,35 }; 45 | 46 | // this structure defines all the variables and events of your control interface 47 | struct { 48 | 49 | // input variables 50 | uint8_t button_1; // =1 if button pressed, else =0 51 | 52 | // output variables 53 | uint8_t led_1_r; // =0..255 LED Red brightness 54 | 55 | // other variable 56 | uint8_t connect_flag; // =1 if wire connected, else =0 57 | 58 | } RemoteXY_1; 59 | 60 | 61 | ///////////////////////////////////////////////////////////// 62 | // Second 63 | 64 | uint8_t const PROGMEM RemoteXY_CONF_PROGMEM_2[] = 65 | { 255,1,0,1,0,19,0,11,27,0, 66 | 1,0,11,7,30,30,94,31,88,0, 67 | 65,4,59,30,21,21 }; 68 | 69 | // this structure defines all the variables and events of your control interface 70 | struct { 71 | 72 | // input variables 73 | uint8_t button_1; // =1 if button pressed, else =0 74 | 75 | // output variables 76 | uint8_t led_1_r; // =0..255 LED Red brightness 77 | 78 | // other variable 79 | uint8_t connect_flag; // =1 if wire connected, else =0 80 | 81 | } RemoteXY_2; 82 | 83 | #pragma pack(pop) 84 | 85 | 86 | 87 | ///////////////////////////////////////////// 88 | // END RemoteXY include // 89 | ///////////////////////////////////////////// 90 | 91 | 92 | CRemoteXY *remotexy_1; 93 | CRemoteXY *remotexy_2; 94 | 95 | void setup() 96 | { 97 | 98 | CRemoteXYComm_WiFi * wifi = new CRemoteXYComm_WiFi ( 99 | "myHomeFiFi", // REMOTEXY_WIFI_SSID 100 | "myPass" // REMOTEXY_WIFI_PASSWORD 101 | ); 102 | 103 | remotexy_1 = new CRemoteXY (RemoteXY_CONF_PROGMEM_1, &RemoteXY_1); 104 | remotexy_1->addConnection (new CRemoteXYConnectionCloud ( wifi, 105 | "cloud.remotexy.com", // REMOTEXY_CLOUD_SERVER 106 | 6376, // REMOTEXY_CLOUD_PORT 107 | "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // REMOTEXY_CLOUD_TOKEN 108 | )); 109 | 110 | remotexy_2 = new CRemoteXY (RemoteXY_CONF_PROGMEM_2, &RemoteXY_2); 111 | remotexy_2->addConnection (new CRemoteXYConnectionCloud ( wifi, 112 | "cloud.remotexy.com", // REMOTEXY_CLOUD_SERVER 113 | 6376, // REMOTEXY_CLOUD_PORT 114 | "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY" // REMOTEXY_CLOUD_TOKEN 115 | )); 116 | 117 | // TODO you setup code 118 | 119 | } 120 | 121 | void loop() 122 | { 123 | remotexy_1->handler (); 124 | remotexy_2->handler (); 125 | 126 | if (RemoteXY_1.button_1) RemoteXY_1.led_1_r = 255; 127 | else RemoteXY_1.led_1_r = 0; 128 | 129 | if (RemoteXY_2.button_1) RemoteXY_2.led_1_r = 255; 130 | else RemoteXY_2.led_1_r = 0; 131 | 132 | // TODO you loop code 133 | // use the RemoteXY structure for data transfer 134 | // do not call delay() 135 | 136 | 137 | } 138 | -------------------------------------------------------------------------------- /examples/Multiple Connection/ESP_WiFiServerAndCloud/ESP_WiFiServerAndCloud.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Example: using server and cloud connections together 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | #define REMOTEXY__DEBUGLOG 24 | 25 | #if defined (ESP8266) 26 | #include 27 | #elif defined (ESP32) 28 | #include 29 | #endif 30 | 31 | #include 32 | 33 | 34 | // RemoteXY configurate 35 | #pragma pack(push, 1) 36 | uint8_t RemoteXY_CONF[] = 37 | { 255,1,0,1,0,27,0,10,13,2, 38 | 1,0,9,9,46,46,6,7,50,50, 39 | 2,31,88,0,65,4,62,16,31,31, 40 | 14,62,35,35 }; 41 | 42 | // this structure defines all the variables and events of your control interface 43 | struct { 44 | 45 | // input variables 46 | uint8_t button_1; // =1 if button pressed, else =0 47 | 48 | // output variables 49 | uint8_t led_1_r; // =0..255 LED Red brightness 50 | 51 | // other variable 52 | uint8_t connect_flag; // =1 if wire connected, else =0 53 | 54 | } RemoteXY; 55 | #pragma pack(pop) 56 | 57 | 58 | 59 | ///////////////////////////////////////////// 60 | // END RemoteXY include // 61 | ///////////////////////////////////////////// 62 | 63 | 64 | CRemoteXY *remotexy; 65 | 66 | void setup() 67 | { 68 | 69 | CRemoteXYComm_WiFi * wifi = new CRemoteXYComm_WiFi ( 70 | "myHomeFiFi", // REMOTEXY_WIFI_SSID 71 | "myPass" // REMOTEXY_WIFI_PASSWORD 72 | ); 73 | 74 | remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY); 75 | 76 | remotexy->addConnection (new CRemoteXYConnectionServer ( wifi, 77 | 6377 // REMOTEXY_SERVER_PORT 78 | )); 79 | 80 | remotexy->addConnection (new CRemoteXYConnectionCloud ( wifi, 81 | "cloud.remotexy.com", // REMOTEXY_CLOUD_SERVER 82 | 6376, // REMOTEXY_CLOUD_PORT 83 | "xxxxxxxxxxxxxxxxxxxxxxxx" // REMOTEXY_CLOUD_TOKEN 84 | )); 85 | 86 | 87 | 88 | // TODO you setup code 89 | 90 | } 91 | 92 | void loop() 93 | { 94 | remotexy->handler (); 95 | 96 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 97 | else RemoteXY.led_1_r = 0; 98 | 99 | // TODO you loop code 100 | // use the RemoteXY structure for data transfer 101 | // do not call delay() 102 | 103 | 104 | } -------------------------------------------------------------------------------- /examples/NRF/BLE/BLE.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Simple button example 3 | 4 | This source code of graphical user interface 5 | has been generated automatically by RemoteXY editor. 6 | To compile this code using RemoteXY library 3.1.1 or later version 7 | download by link http://remotexy.com/en/library/ 8 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 9 | - for ANDROID 4.5.1 or later version; 10 | - for iOS 1.4.1 or later version; 11 | 12 | This source code is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | */ 17 | 18 | ////////////////////////////////////////////// 19 | // RemoteXY include library // 20 | ////////////////////////////////////////////// 21 | 22 | // RemoteXY select connection mode and include library 23 | //#define REMOTEXY__DEBUGLOG 24 | 25 | #include 26 | #include 27 | 28 | 29 | // RemoteXY configurate 30 | #pragma pack(push, 1) 31 | uint8_t RemoteXY_CONF[] = 32 | { 255,1,0,1,0,27,0,10,13,2, 33 | 1,0,9,9,46,46,6,7,50,50, 34 | 2,31,88,0,65,4,62,16,31,31, 35 | 14,62,35,35 }; 36 | 37 | // this structure defines all the variables and events of your control interface 38 | struct { 39 | 40 | // input variables 41 | uint8_t button_1; // =1 if button pressed, else =0 42 | 43 | // output variables 44 | uint8_t led_1_r; // =0..255 LED Red brightness 45 | 46 | // other variable 47 | uint8_t connect_flag; // =1 if wire connected, else =0 48 | 49 | } RemoteXY; 50 | #pragma pack(pop) 51 | 52 | 53 | 54 | ///////////////////////////////////////////// 55 | // END RemoteXY include // 56 | ///////////////////////////////////////////// 57 | 58 | 59 | CRemoteXY *remotexy; 60 | 61 | void setup() 62 | { 63 | remotexy = new CRemoteXY ( 64 | RemoteXY_CONF_PROGMEM, 65 | &RemoteXY, 66 | new CRemoteXYStream_BLEPeripheral ( 67 | "myRemoteXY" // REMOTEXY_BLUETOOTH_NAME 68 | ) 69 | ); 70 | 71 | 72 | // TODO you setup code 73 | 74 | } 75 | 76 | void loop() 77 | { 78 | remotexy->handler (); 79 | 80 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 81 | else RemoteXY.led_1_r = 0; 82 | 83 | // TODO you loop code 84 | // use the RemoteXY structure for data transfer 85 | // do not call delay() 86 | 87 | 88 | } -------------------------------------------------------------------------------- /examples/STM32/USBonChip_OTG/USBonChip_OTG.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Example of USB connection to USB OTG phone. 3 | Built-in on chip USB is used. 4 | Board: STM32F103 5 | 6 | This source code of graphical user interface 7 | has been generated automatically by RemoteXY editor. 8 | To compile this code using RemoteXY library 3.1.11 or later version 9 | download by link http://remotexy.com/en/library/ 10 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 11 | - for ANDROID 4.5.1 or later version; 12 | - for iOS 1.4.1 or later version; 13 | 14 | This source code is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU Lesser General Public 16 | License as published by the Free Software Foundation; either 17 | version 2.1 of the License, or (at your option) any later version. 18 | */ 19 | 20 | ////////////////////////////////////////////// 21 | // RemoteXY include library // 22 | ////////////////////////////////////////////// 23 | 24 | // RemoteXY select connection mode and include library 25 | //#define REMOTEXY__DEBUGLOG 26 | 27 | #include 28 | 29 | 30 | // RemoteXY configurate 31 | #pragma pack(push, 1) 32 | uint8_t RemoteXY_CONF[] = 33 | { 255,1,0,1,0,27,0,10,13,2, 34 | 1,0,9,9,46,46,6,7,50,50, 35 | 2,31,88,0,65,4,62,16,31,31, 36 | 14,62,35,35 }; 37 | 38 | // this structure defines all the variables and events of your control interface 39 | struct { 40 | 41 | // input variables 42 | uint8_t button_1; // =1 if button pressed, else =0 43 | 44 | // output variables 45 | uint8_t led_1_r; // =0..255 LED Red brightness 46 | 47 | // other variable 48 | uint8_t connect_flag; // =1 if wire connected, else =0 49 | 50 | } RemoteXY; 51 | #pragma pack(pop) 52 | 53 | 54 | 55 | ///////////////////////////////////////////// 56 | // END RemoteXY include // 57 | ///////////////////////////////////////////// 58 | 59 | 60 | CRemoteXY *remotexy; 61 | 62 | void setup() 63 | { 64 | 65 | remotexy = new CRemoteXY ( 66 | RemoteXY_CONF_PROGMEM, 67 | &RemoteXY, 68 | new CRemoteXYStream_USBSerial ( 69 | &Serial, 70 | 115200 // REMOTEXY_SERIAL_SPEED 71 | ) 72 | ); 73 | 74 | 75 | // TODO you setup code 76 | 77 | } 78 | 79 | void loop() 80 | { 81 | remotexy->handler (); 82 | 83 | if (RemoteXY.button_1) RemoteXY.led_1_r = 255; 84 | else RemoteXY.led_1_r = 0; 85 | 86 | // TODO you loop code 87 | // use the RemoteXY structure for data transfer 88 | // do not call delay() 89 | 90 | 91 | } -------------------------------------------------------------------------------- /examples/Setup Connection/ESP_WiFiAndCloudSetupUsingAP/ESP_WiFiAndCloudSetupUsingAP.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Example to setup WiFi client and cloud server settings using open access point mode 3 | for ESP32 or ESP8266 4 | 5 | This source code of graphical user interface 6 | has been generated automatically by RemoteXY editor. 7 | To compile this code using RemoteXY library 3.1.1 or later version 8 | download by link http://remotexy.com/en/library/ 9 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 10 | - for ANDROID 4.10.1 or later version; 11 | - for iOS 1.8.1 or later version; 12 | 13 | This source code is free software; you can redistribute it and/or 14 | modify it under the terms of the GNU Lesser General Public 15 | License as published by the Free Software Foundation; either 16 | version 2.1 of the License, or (at your option) any later version. 17 | */ 18 | //#define REMOTEXY__DEBUGLOG 19 | 20 | #include 21 | #if defined (ESP8266) 22 | #include 23 | #elif defined (ESP32) 24 | #include 25 | #endif 26 | 27 | #include 28 | 29 | #define PIN_BUTTON_WIFISETUP 3 // pin of button for wifi settings, press this button when devise reset 30 | #define REMOTEXY_SERVER_PORT 6377 31 | #define DEVICE_NAME "RemoteXY" 32 | 33 | #define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com" // url of cloud server, does not change 34 | #define REMOTEXY_CLOUD_PORT 6376 // port for cloud server, does not change 35 | 36 | #pragma pack(push, 1) 37 | //////////////////////////////////////// 38 | // WiFi+Cloud settings configuration 39 | //////////////////////////////////////// 40 | 41 | #define ssidLength 21 // 20 chars max + zero 42 | #define passLength 21 // 20 chars max + zero 43 | #define tokenLength 33 // 32 chars max + zero 44 | #define checkLength 1 // 1 byte 45 | #define EPPROMLength ssidLength+passLength+tokenLength+checkLength 46 | 47 | #define ssid_EPPROM 0x0000 48 | #define pass_EPPROM ssid_EPPROM+ssidLength 49 | #define token_EPPROM ssid_EPPROM+ssidLength+passLength 50 | #define check_EPPROM ssid_EPPROM+ssidLength+passLength+tokenLength 51 | #define checkValueForEPPROM 0x55 52 | 53 | uint8_t const PROGMEM RemoteXY_CONF_WiFiSettings [] = 54 | { 255,76,0,0,0,149,0,15,172,2, 55 | 7,4,28,9,47,6,9,15,46,6, 56 | 24,31,2,21,7,4,28,21,47,6, 57 | 9,30,46,6,24,31,2,21,129,0, 58 | 28,5,34,4,9,10,35,4,31,87, 59 | 105,70,105,32,110,97,109,101,32,40, 60 | 83,83,73,68,41,58,0,129,0,28, 61 | 17,35,4,9,25,35,4,31,87,105, 62 | 70,105,32,112,97,115,115,119,111,114, 63 | 100,58,0,129,0,28,32,30,4,9, 64 | 42,25,4,31,67,108,111,117,100,32, 65 | 116,111,107,101,110,58,0,7,4,28, 66 | 36,47,6,9,47,46,6,24,31,2, 67 | 33,1,2,28,51,47,8,8,83,48, 68 | 8,190,31,82,69,83,69,84,32,68, 69 | 69,86,73,67,69,0 }; 70 | 71 | struct { 72 | 73 | // input variables 74 | char ssid[21]; // string UTF8 end zero 75 | char pass[21]; // string UTF8 end zero 76 | char token[33]; // string UTF8 end zero 77 | uint8_t buttonReset; // =1 if button pressed, else =0 78 | 79 | // other variable 80 | uint8_t connect_flag; // =1 if wire connected, else =0 81 | 82 | } RemoteXY_WiFiSettings; 83 | 84 | //////////////////////////////////////// 85 | // Main configuration 86 | //////////////////////////////////////// 87 | uint8_t RemoteXY_CONF[] = 88 | { 255,4,0,2,0,245,0,10,8,2, 89 | 130,1,3,22,36,19,2,30,35,23, 90 | 8,130,1,3,42,36,18,2,58,35, 91 | 25,8,129,0,6,30,18,6,4,75, 92 | 0,6,8,0,66,1,44,3,36,47, 93 | 41,6,10,77,5,26,129,0,82,45, 94 | 9,6,53,79,6,4,17,48,37,0, 95 | 129,0,82,24,9,6,53,42,8,4, 96 | 17,53,48,37,0,129,0,81,3,15, 97 | 6,52,7,11,4,17,49,48,48,37, 98 | 0,7,54,4,30,32,10,4,70,32, 99 | 11,5,26,5,129,0,4,23,31,6, 100 | 4,64,24,5,16,65,117,116,111,32, 101 | 108,101,118,101,108,58,0,2,0,4, 102 | 10,31,10,4,12,31,10,2,26,31, 103 | 31,77,65,78,85,65,76,0,65,85, 104 | 84,79,0,129,0,3,3,34,6,4, 105 | 5,29,5,16,80,117,109,112,32,109, 106 | 111,100,101,0,129,0,4,43,21,6, 107 | 4,32,18,5,16,77,97,110,117,97, 108 | 108,0,2,0,4,49,31,10,4,39, 109 | 31,10,2,26,31,31,79,78,0,79, 110 | 70,70,0,65,4,48,52,9,9,16, 111 | 87,9,9,129,0,60,54,18,6,28, 112 | 89,26,6,11,80,117,109,112,32,111, 113 | 110,0 }; 114 | 115 | struct { 116 | 117 | // input variables 118 | int16_t edit_level; // 32767.. +32767 119 | uint8_t switch_manual; // =1 if switch ON and =0 if OFF 120 | uint8_t switch_pump; // =1 if switch ON and =0 if OFF 121 | 122 | // output variables 123 | int8_t level; // =0..100 level position 124 | uint8_t led_on_r; // =0..255 LED Red brightness 125 | 126 | // other variable 127 | uint8_t connect_flag; // =1 if wire connected, else =0 128 | 129 | } RemoteXY; 130 | 131 | #pragma pack(pop) 132 | 133 | 134 | 135 | ///////////////////////////////////////////// 136 | // END RemoteXY include // 137 | ///////////////////////////////////////////// 138 | 139 | 140 | CRemoteXY *remotexy; 141 | uint8_t wifiSettingMode = 0; 142 | 143 | boolean readRemoteXYFromEEPROM () { 144 | if (EEPROM.read(check_EPPROM) == checkValueForEPPROM) { 145 | for (uint8_t i = 0; ihandler (); 188 | 189 | if (wifiSettingMode) { 190 | 191 | if (RemoteXY_WiFiSettings.buttonReset) { 192 | writeRemoteXYToEEPROM (); 193 | ESP.restart (); 194 | } 195 | } 196 | else myLoop(); 197 | 198 | } 199 | 200 | 201 | float level = 50; 202 | int pump = 0; 203 | uint32_t prevMillis = 0; 204 | 205 | 206 | void myLoop() { 207 | 208 | // TODO you loop code 209 | // example code 210 | uint32_t t = millis (); 211 | if (t>prevMillis) { 212 | float dt = float (t - prevMillis)/1000.0; 213 | prevMillis = t; 214 | 215 | //Serial.println (dt); 216 | 217 | if (RemoteXY.switch_manual == 1) { 218 | pump = RemoteXY.switch_pump; 219 | } 220 | else { 221 | if (pump==0) { 222 | if (level > RemoteXY.edit_level) pump = 1; 223 | } 224 | else { 225 | if (level < RemoteXY.edit_level-10) pump = 0; 226 | } 227 | } 228 | 229 | level = level + dt; 230 | if (pump != 0) level = level - dt*3; 231 | if (level<0) level = 0; 232 | if (level>100) level = 100; 233 | 234 | RemoteXY.level = level; 235 | RemoteXY.led_on_r = (pump==0)?0:255; 236 | } 237 | // END example code 238 | } 239 | -------------------------------------------------------------------------------- /examples/Setup Connection/ESP_WiFiSetupUsingAP/ESP_WiFiSetupUsingAP.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Example to setup WiFi client settings using open access point mode 3 | for ESP32 or ESP8266 4 | 5 | This source code of graphical user interface 6 | has been generated automatically by RemoteXY editor. 7 | To compile this code using RemoteXY library 3.1.1 or later version 8 | download by link http://remotexy.com/en/library/ 9 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 10 | - for ANDROID 4.10.1 or later version; 11 | - for iOS 1.8.1 or later version; 12 | 13 | This source code is free software; you can redistribute it and/or 14 | modify it under the terms of the GNU Lesser General Public 15 | License as published by the Free Software Foundation; either 16 | version 2.1 of the License, or (at your option) any later version. 17 | */ 18 | //#define REMOTEXY__DEBUGLOG 19 | 20 | #include 21 | #if defined (ESP8266) 22 | #include 23 | #elif defined (ESP32) 24 | #include 25 | #endif 26 | 27 | #include 28 | 29 | #define PIN_BUTTON_WIFISETUP 3 // pin of button for wifi settings, press this button when devise reset 30 | #define REMOTEXY_SERVER_PORT 6377 31 | #define DEVICE_NAME "RemoteXY" 32 | 33 | #pragma pack(push, 1) 34 | //////////////////////////////////////// 35 | // WiFi settings configuration 36 | //////////////////////////////////////// 37 | 38 | #define ssidLength 21 // 20 chars max + zero 39 | #define passLength 21 // 20 chars max + zero 40 | #define checkLength 1 // 1 byte 41 | #define EPPROMLength ssidLength+passLength+checkLength 42 | 43 | #define ssid_EPPROM 0x0000 44 | #define pass_EPPROM ssid_EPPROM+ssidLength 45 | #define check_EPPROM ssid_EPPROM+ssidLength+passLength 46 | #define checkValueForEPPROM 0x55 47 | 48 | uint8_t const PROGMEM RemoteXY_CONF_WiFiSettings [] = 49 | { 255,43,0,0,0,106,0,10,172,2, 50 | 7,4,28,18,47,7,9,25,46,7, 51 | 24,31,2,21,7,4,28,34,47,7, 52 | 9,44,46,7,24,31,2,21,129,0, 53 | 28,13,34,4,9,20,35,4,31,87, 54 | 105,70,105,32,110,97,109,101,32,40, 55 | 83,83,73,68,41,58,0,129,0,28, 56 | 29,35,4,9,39,35,4,31,80,97, 57 | 115,115,119,111,114,100,58,0,1,2, 58 | 28,46,47,8,8,61,48,8,190,31, 59 | 82,69,83,69,84,32,68,69,86,73, 60 | 67,69,0 }; 61 | 62 | struct { 63 | 64 | // input variables 65 | char ssid[21]; // =строка UTF8 оканчивающаяся нулем 66 | char pass[21]; // =строка UTF8 оканчивающаяся нулем 67 | uint8_t buttonReset; // =1 если кнопка нажата, иначе =0 68 | 69 | // other variable 70 | uint8_t connect_flag; // =1 if wire connected, else =0 71 | 72 | 73 | } RemoteXY_WiFiSettings; 74 | 75 | //////////////////////////////////////// 76 | // Main configuration 77 | //////////////////////////////////////// 78 | uint8_t RemoteXY_CONF[] = 79 | { 255,4,0,2,0,245,0,10,8,2, 80 | 130,1,3,22,36,19,2,30,35,23, 81 | 8,130,1,3,42,36,18,2,58,35, 82 | 25,8,129,0,6,30,18,6,4,75, 83 | 0,6,8,0,66,1,44,3,36,47, 84 | 41,6,10,77,5,26,129,0,82,45, 85 | 9,6,53,79,6,4,17,48,37,0, 86 | 129,0,82,24,9,6,53,42,8,4, 87 | 17,53,48,37,0,129,0,81,3,15, 88 | 6,52,7,11,4,17,49,48,48,37, 89 | 0,7,54,4,30,32,10,4,70,32, 90 | 11,5,26,5,129,0,4,23,31,6, 91 | 4,64,24,5,16,65,117,116,111,32, 92 | 108,101,118,101,108,58,0,2,0,4, 93 | 10,31,10,4,12,31,10,2,26,31, 94 | 31,77,65,78,85,65,76,0,65,85, 95 | 84,79,0,129,0,3,3,34,6,4, 96 | 5,29,5,16,80,117,109,112,32,109, 97 | 111,100,101,0,129,0,4,43,21,6, 98 | 4,32,18,5,16,77,97,110,117,97, 99 | 108,0,2,0,4,49,31,10,4,39, 100 | 31,10,2,26,31,31,79,78,0,79, 101 | 70,70,0,65,4,48,52,9,9,16, 102 | 87,9,9,129,0,60,54,18,6,28, 103 | 89,26,6,11,80,117,109,112,32,111, 104 | 110,0 }; 105 | 106 | struct { 107 | 108 | // input variables 109 | int16_t edit_level; // 32767.. +32767 110 | uint8_t switch_manual; // =1 if switch ON and =0 if OFF 111 | uint8_t switch_pump; // =1 if switch ON and =0 if OFF 112 | 113 | // output variables 114 | int8_t level; // =0..100 level position 115 | uint8_t led_on_r; // =0..255 LED Red brightness 116 | 117 | // other variable 118 | uint8_t connect_flag; // =1 if wire connected, else =0 119 | 120 | } RemoteXY; 121 | 122 | #pragma pack(pop) 123 | 124 | 125 | 126 | ///////////////////////////////////////////// 127 | // END RemoteXY include // 128 | ///////////////////////////////////////////// 129 | 130 | 131 | CRemoteXY *remotexy; 132 | uint8_t wifiSettingMode = 0; 133 | 134 | boolean readRemoteXYFromEEPROM () { 135 | if (EEPROM.read(check_EPPROM) == checkValueForEPPROM) { 136 | for (uint8_t i = 0; ihandler (); 180 | 181 | if (wifiSettingMode) { 182 | 183 | if (RemoteXY_WiFiSettings.buttonReset) { 184 | writeRemoteXYToEEPROM (); 185 | ESP.restart (); 186 | } 187 | } 188 | else myLoop(); 189 | 190 | } 191 | 192 | 193 | float level = 50; 194 | int pump = 0; 195 | uint32_t prevMillis = 0; 196 | 197 | 198 | void myLoop() { 199 | 200 | // TODO you loop code 201 | 202 | // example code 203 | uint32_t t = millis (); 204 | if (t>prevMillis) { 205 | float dt = float (t - prevMillis)/1000.0; 206 | prevMillis = t; 207 | 208 | //Serial.println (dt); 209 | 210 | if (RemoteXY.switch_manual == 1) { 211 | pump = RemoteXY.switch_pump; 212 | } 213 | else { 214 | if (pump==0) { 215 | if (level > RemoteXY.edit_level) pump = 1; 216 | } 217 | else { 218 | if (level < RemoteXY.edit_level-10) pump = 0; 219 | } 220 | } 221 | 222 | level = level + dt; 223 | if (pump != 0) level = level - dt*3; 224 | if (level<0) level = 0; 225 | if (level>100) level = 100; 226 | 227 | RemoteXY.level = level; 228 | RemoteXY.led_on_r = (pump==0)?0:255; 229 | } 230 | // END example code 231 | } 232 | -------------------------------------------------------------------------------- /examples/Setup Connection/ESP_WiFiSetupUsingBLE/ESP_WiFiSetupUsingBLE.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Example to setup WiFi client settings using BLE mode 3 | for ESP32 4 | 5 | This source code of graphical user interface 6 | has been generated automatically by RemoteXY editor. 7 | To compile this code using RemoteXY library 3.1.1 or later version 8 | download by link http://remotexy.com/en/library/ 9 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 10 | - for ANDROID 4.5.1 or later version; 11 | - for iOS 1.4.1 or later version; 12 | 13 | This source code is free software; you can redistribute it and/or 14 | modify it under the terms of the GNU Lesser General Public 15 | License as published by the Free Software Foundation; either 16 | version 2.1 of the License, or (at your option) any later version. 17 | */ 18 | //#define REMOTEXY__DEBUGLOG 19 | 20 | #include 21 | #include 22 | #include "BLEDevice.h" 23 | 24 | #include 25 | 26 | #define PIN_BUTTON_WIFISETUP 3 // pin of button for wifi settings, press this button when devise reset 27 | #define DEVICE_NAME "RemoteXY" 28 | #define REMOTEXY_SERVER_PORT 6377 29 | 30 | #pragma pack(push, 1) 31 | //////////////////////////////////////// 32 | // WiFi settings configuration 33 | //////////////////////////////////////// 34 | 35 | #define ssidLength 21 // 20 chars max + zero 36 | #define passLength 21 // 20 chars max + zero 37 | #define checkLength 1 // 1 byte 38 | #define EPPROMLength ssidLength+passLength+checkLength 39 | 40 | #define ssid_EPPROM 0x0000 41 | #define pass_EPPROM ssid_EPPROM+ssidLength 42 | #define check_EPPROM ssid_EPPROM+ssidLength+passLength 43 | #define checkValueForEPPROM 0x55 44 | 45 | uint8_t const PROGMEM RemoteXY_CONF_WiFiSettings [] = 46 | { 255,43,0,0,0,106,0,10,172,2, 47 | 7,4,28,18,47,7,9,25,46,7, 48 | 24,31,2,21,7,4,28,34,47,7, 49 | 9,44,46,7,24,31,2,21,129,0, 50 | 28,13,34,4,9,20,35,4,31,87, 51 | 105,70,105,32,110,97,109,101,32,40, 52 | 83,83,73,68,41,58,0,129,0,28, 53 | 29,35,4,9,39,35,4,31,80,97, 54 | 115,115,119,111,114,100,58,0,1,2, 55 | 28,46,47,8,8,61,48,8,190,31, 56 | 82,69,83,69,84,32,68,69,86,73, 57 | 67,69,0 }; 58 | 59 | struct { 60 | 61 | // input variables 62 | char ssid[21]; // =строка UTF8 оканчивающаяся нулем 63 | char pass[21]; // =строка UTF8 оканчивающаяся нулем 64 | uint8_t buttonReset; // =1 если кнопка нажата, иначе =0 65 | 66 | // other variable 67 | uint8_t connect_flag; // =1 if wire connected, else =0 68 | 69 | 70 | } RemoteXY_WiFiSettings; 71 | 72 | //////////////////////////////////////// 73 | // Main configuration 74 | //////////////////////////////////////// 75 | uint8_t RemoteXY_CONF[] = 76 | { 255,4,0,2,0,245,0,10,8,2, 77 | 130,1,3,22,36,19,2,30,35,23, 78 | 8,130,1,3,42,36,18,2,58,35, 79 | 25,8,129,0,6,30,18,6,4,75, 80 | 0,6,8,0,66,1,44,3,36,47, 81 | 41,6,10,77,5,26,129,0,82,45, 82 | 9,6,53,79,6,4,17,48,37,0, 83 | 129,0,82,24,9,6,53,42,8,4, 84 | 17,53,48,37,0,129,0,81,3,15, 85 | 6,52,7,11,4,17,49,48,48,37, 86 | 0,7,54,4,30,32,10,4,70,32, 87 | 11,5,26,5,129,0,4,23,31,6, 88 | 4,64,24,5,16,65,117,116,111,32, 89 | 108,101,118,101,108,58,0,2,0,4, 90 | 10,31,10,4,12,31,10,2,26,31, 91 | 31,77,65,78,85,65,76,0,65,85, 92 | 84,79,0,129,0,3,3,34,6,4, 93 | 5,29,5,16,80,117,109,112,32,109, 94 | 111,100,101,0,129,0,4,43,21,6, 95 | 4,32,18,5,16,77,97,110,117,97, 96 | 108,0,2,0,4,49,31,10,4,39, 97 | 31,10,2,26,31,31,79,78,0,79, 98 | 70,70,0,65,4,48,52,9,9,16, 99 | 87,9,9,129,0,60,54,18,6,28, 100 | 89,26,6,11,80,117,109,112,32,111, 101 | 110,0 }; 102 | 103 | struct { 104 | 105 | // input variables 106 | int16_t edit_level; // 32767.. +32767 107 | uint8_t switch_manual; // =1 if switch ON and =0 if OFF 108 | uint8_t switch_pump; // =1 if switch ON and =0 if OFF 109 | 110 | // output variables 111 | int8_t level; // =0..100 level position 112 | uint8_t led_on_r; // =0..255 LED Red brightness 113 | 114 | // other variable 115 | uint8_t connect_flag; // =1 if wire connected, else =0 116 | 117 | } RemoteXY; 118 | 119 | #pragma pack(pop) 120 | 121 | 122 | 123 | ///////////////////////////////////////////// 124 | // END RemoteXY include // 125 | ///////////////////////////////////////////// 126 | 127 | 128 | CRemoteXY *remotexy; 129 | uint8_t wifiSettingMode = 0; 130 | 131 | 132 | boolean readRemoteXYFromEEPROM () { 133 | if (EEPROM.read(check_EPPROM) == checkValueForEPPROM) { 134 | for (uint8_t i = 0; ihandler (); 176 | 177 | if (wifiSettingMode) { 178 | 179 | if (RemoteXY_WiFiSettings.buttonReset) { 180 | writeRemoteXYToEEPROM (); 181 | ESP.restart (); 182 | } 183 | } 184 | else myLoop(); 185 | 186 | } 187 | 188 | 189 | float level = 50; 190 | int pump = 0; 191 | uint32_t prevMillis = 0; 192 | 193 | 194 | void myLoop() { 195 | 196 | // TODO you loop code 197 | 198 | // example code 199 | uint32_t t = millis (); 200 | if (t>prevMillis) { 201 | float dt = float (t - prevMillis)/1000.0; 202 | prevMillis = t; 203 | 204 | //Serial.println (dt); 205 | 206 | if (RemoteXY.switch_manual == 1) { 207 | pump = RemoteXY.switch_pump; 208 | } 209 | else { 210 | if (pump==0) { 211 | if (level > RemoteXY.edit_level) pump = 1; 212 | } 213 | else { 214 | if (level < RemoteXY.edit_level-10) pump = 0; 215 | } 216 | } 217 | 218 | level = level + dt; 219 | if (pump != 0) level = level - dt*3; 220 | if (level<0) level = 0; 221 | if (level>100) level = 100; 222 | 223 | RemoteXY.level = level; 224 | RemoteXY.led_on_r = (pump==0)?0:255; 225 | } 226 | // END example code 227 | } 228 | -------------------------------------------------------------------------------- /examples/Various/AnyStreamClass/AnyStreamClass.pde: -------------------------------------------------------------------------------- 1 | /* 2 | The example shows how any data stream can be used. 3 | Any class inherited from the Arduino Stream class can be connected to RemoteXY 4 | 5 | 6 | This source code of graphical user interface 7 | has been generated automatically by RemoteXY editor. 8 | To compile this code using RemoteXY library 3.1.11 or later version 9 | download by link http://remotexy.com/en/library/ 10 | To connect using RemoteXY mobile app by link http://remotexy.com/en/download/ 11 | - for ANDROID 4.11.4 or later version; 12 | - for iOS 1.9.1 or later version; 13 | 14 | This source code is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU Lesser General Public 16 | License as published by the Free Software Foundation; either 17 | version 2.1 of the License, or (at your option) any later version. 18 | */ 19 | 20 | 21 | #include 22 | 23 | 24 | // RemoteXY configurate 25 | #pragma pack(push, 1) 26 | uint8_t RemoteXY_CONF[] = // 28 bytes 27 | { 255,1,0,1,0,21,0,16,31,1,70,16,16,55,34,34,26,37,0,1, 28 | 0,15,8,34,34,2,31,0 }; 29 | 30 | // this structure defines all the variables and events of your control interface 31 | struct { 32 | 33 | // input variables 34 | uint8_t button_1; // =1 if button pressed, else =0 35 | 36 | // output variables 37 | uint8_t led_1; // led state 0 .. 1 38 | 39 | // other variable 40 | uint8_t connect_flag; // =1 if wire connected, else =0 41 | 42 | } RemoteXY; 43 | #pragma pack(pop) 44 | 45 | CRemoteXY *remotexy; 46 | 47 | void setup() 48 | { 49 | 50 | Serial.begin (9600); 51 | 52 | remotexy = new CRemoteXY ( 53 | RemoteXY_CONF_PROGMEM, 54 | &RemoteXY, 55 | &Serial 56 | ); 57 | 58 | 59 | // TODO you setup code 60 | 61 | } 62 | 63 | void loop() 64 | { 65 | remotexy->handler (); 66 | 67 | RemoteXY.led_1 = RemoteXY.button_1; 68 | 69 | // TODO you loop code 70 | // use the RemoteXY structure for data transfer 71 | // do not call delay(), use instead remotexy->delay() 72 | 73 | 74 | } -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ###################################### 2 | # Syntax Coloring Map For RemoteXY # 3 | ###################################### 4 | 5 | RemoteXY KEYWORD1 6 | RemoteXY_Init KEYWORD2 7 | RemoteXY_Handler KEYWORD2 8 | RemoteXY_delay KEYWORD2 9 | RemoteXY_isConnected KEYWORD2 -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=RemoteXY 2 | version=3.1.14 3 | author=Evgeny Shemanuev, RemoteXY 4 | maintainer=RemoteXY 5 | sentence=For all RemoteXY projects. 6 | paragraph=The library is part of the RemoteXY project.
RemoteXY allows you to control your device using an Android or iOS smartphone. There are Bluetooth, USB OTG, WiFi, Ethernet or Cloud server can be used for connection. To make GUI go to the web site http://remotexy.com 7 | category=Communication 8 | url=http://remotexy.com/en/help/ 9 | architectures=* 10 | -------------------------------------------------------------------------------- /src/RemoteXY.h: -------------------------------------------------------------------------------- 1 | /* RemoteXY.h 2 | A RemoteXY Library - Remote device control 3 | version 3.1.14 4 | =========================================================== 5 | For use RemoteXY library visit website http://remotexy.com 6 | This website will help you use the library for configuring 7 | a remote control from a smartphone or tablet. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | Supported modes: 15 | All boards: 16 | #define REMOTEXY_MODE__HARDSERIAL - direct data transfer via HARDSERIAL 17 | #define REMOTEXY_MODE__SOFTSERIAL - direct data transfer via SOFTSERIAL 18 | #define REMOTEXY_MODE__ALTSOFTSERIAL - direct data transfer via AltSoftSerial.h library 19 | #define REMOTEXY_MODE__USBSERIAL - direct data transfer via USB CDC for ATmega32u4, STM32 20 | #define REMOTEXY_MODE__ETHERNET - data transfer using library and open server 21 | #define REMOTEXY_MODE__ETHERNET_CLOUD - data transfer using library and cloud connection 22 | #define REMOTEXY_MODE__HARDSERIAL_ESP8266 - data transfer via HARDSERIAL using AT commands of ESP8266 and open server 23 | #define REMOTEXY_MODE__HARDSERIAL_ESP8266_POINT - data transfer via HARDSERIAL using AT commands of ESP8266 and open access point with a server 24 | #define REMOTEXY_MODE__HARDSERIAL_ESP8266_CLOUD - data transfer via HARDSERIAL using AT commands of ESP8266 and cloud connection 25 | #define REMOTEXY_MODE__SOFTSERIAL_ESP8266 - data transfer via SOFTSERIAL using AT commands of ESP8266 and open server 26 | #define REMOTEXY_MODE__SOFTSERIAL_ESP8266_POINT - data transfer via SOFTSERIAL using AT commands of ESP8266 and open access point with a server 27 | #define REMOTEXY_MODE__SOFTSERIAL_ESP8266_CLOUD - data transfer via SOFTSERIAL using AT commands of ESP8266 and cloud connection 28 | #define REMOTEXY_MODE__ALTSOFTSERIAL_ESP8266 - data transfer via AltSoftSerial.h library using AT commands of ESP8266 and open server 29 | #define REMOTEXY_MODE__ALTSOFTSERIAL_ESP8266_POINT - data transfer via AltSoftSerial.h library using AT commands of ESP8266 and open access point with a server 30 | #define REMOTEXY_MODE__ALTSOFTSERIAL_ESP8266_CLOUD - data transfer via AltSoftSerial.h library using AT commands of ESP8266 and cloud connection 31 | #define REMOTEXY_MODE__WIFI - data transfer using generic wifi.h (esp8266wifi.h, WiFiS3.h) library and open server 32 | #define REMOTEXY_MODE__WIFI_POINT - data transfer using generic wifi.h (esp8266wifi.h, WiFiS3.h) library and open access point with a server 33 | #define REMOTEXY_MODE__WIFI_CLOUD - data transfer using generic wifi.h (esp8266wifi.h, WiFiS3.h) library and cloud connection 34 | 35 | Only ESP32 boards: 36 | #define REMOTEXY_MODE__ESP32CORE_BLE - data transfer using library 37 | #define REMOTEXY_MODE__ESP32CORE_BLUETOOTH - data transfer using library 38 | 39 | Only NRF52xx based boards: 40 | #define REMOTEXY_MODE__NRFCORE_BLEPERIPHERAL - data transfer using library 41 | 42 | Boards supporting the ArduinoBLE.h library: 43 | #define REMOTEXY_MODE__ARDUINOBLE - data transfer using library 44 | 45 | Parameters depending on the selected mode (for example): 46 | #define REMOTEXY_SERIAL Serial // for Hardware Serial 47 | #define REMOTEXY_SERIAL_SPEED 115200 48 | #define REMOTEXY_SERIAL_RX 2 // for Software Serial 49 | #define REMOTEXY_SERIAL_TX 3 // for Software Serial 50 | #define REMOTEXY_WIFI_SSID "RemoteXY" 51 | #define REMOTEXY_WIFI_PASSWORD "1234567890" 52 | #define REMOTEXY_ETHERNET_MAC "DE:AD:BE:EF:EF:ED" // for Ethernet modules 53 | #define REMOTEXY_SERVER_PORT 6377 54 | #define REMOTEXY_BLUETOOTH_NAME "remotexy" // for ESP32 55 | #define REMOTEXY_CLOUD_TOKEN "xxxx" // for Cloud 56 | #define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com" // for Cloud 57 | #define REMOTEXY_CLOUD_PORT 6376 // for Cloud 58 | #define REMOTEXY_ACCESS_PASSWORD "1" 59 | 60 | Debug log info on serial 115200 (define before include this library): 61 | #define REMOTEXY__DEBUGLOG 62 | #define REMOTEXY__DEBUGLOG_SERIAL Serial 63 | #define REMOTEXY__DEBUGLOG_SPEED 115200 64 | 65 | = Version history ======================================== 66 | 67 | version 2.2.5 68 | - support MPIDE; 69 | version 2.3.1 70 | - Support the device access password; 71 | - Support the cloud server as beta test; 72 | - Fixed a bug where the length of variables more than 255; 73 | - Fixed a bug where ESP module reboot and device did not see it; 74 | - Fixed a bug where the connection was filed and the device 75 | did not see it and reconnection is impossible 76 | version 2.3.4 77 | - Fixed a bug where the length of all input variables more than 256; 78 | - Fixed a bug where millis() overflow in 50 days; 79 | - Fixed some bugs; 80 | version 2.3.5 81 | - Fixed some bugs; 82 | version 2.4.1 83 | - support ESP32 WiFi and Bluetooth 84 | version 2.4.2 85 | - Fixed some bugs; 86 | version 2.4.3 87 | - Fixed some bugs; 88 | version 2.4.4 89 | - Fixed ESP32 BLE bugs; 90 | version 3.1.1 91 | - Full update the library: multiple connections, set input variables from board and more; 92 | version 3.1.3 93 | - Multiple connection for cloud, fixed some bugs; 94 | version 3.1.4 95 | - fixed some bugs; 96 | version 3.1.5 97 | - add NRF5XXX and BLEPeripheral.h library as Beta, need define REMOTEXY_MODE__NRFCORE_BLEPERIPHERAL; 98 | version 3.1.6 99 | - fixed some bugs; 100 | version 3.1.7 101 | - add USB CDC Serial for Leonardo, Micro, ..; 102 | version 3.1.8 103 | - fixed some bugs; 104 | version 3.1.9 105 | - added function RemoteXY_delay (ms) as alternative delay (ms); 106 | version 3.1.10 107 | - added support for AltSoftSerial.h library; 108 | - support SoftwareSerial.h for ESP8266; 109 | version 3.1.11 110 | - added support USB CDC serial for STM32; 111 | version 3.1.12 112 | - fixed some bugs; 113 | - any Stream class can be used for communication: example/RemoteXY/Various/AnyStreamClass.pde 114 | version 3.1.13 115 | - fixed some bugs; 116 | - added support for the arduinoBLE.h library 117 | - added support for the WiFiS3.h library, which uses Arduino UNO R4 WiFi 118 | version 3.1.14 119 | - support ESP32 ver.3.0.x 120 | 121 | */ 122 | 123 | #ifndef _REMOTEXY_H_ 124 | #define _REMOTEXY_H_ 125 | 126 | 127 | 128 | #ifndef REMOTEXY_MAX_CLIENTS 129 | #define REMOTEXY_MAX_CLIENTS 4 130 | #endif 131 | 132 | 133 | //#define REMOTEXY__DEBUGLOG 134 | //#define REMOTEXY__DEBUGLOG_SERIAL Serial 135 | //#define REMOTEXY__DEBUGLOG_SPEED 115200 136 | 137 | 138 | #include 139 | #include 140 | #include "RemoteXYDebugLog.h" 141 | 142 | #if defined(REMOTEXY_MODE__ESP32CORE_BLUETOOTH) 143 | #include "BluetoothSerial.h" 144 | #elif defined(REMOTEXY_MODE__ESP32CORE_BLE) 145 | #include "BLEDevice.h" 146 | 147 | #endif 148 | 149 | 150 | #include "RemoteXYApi.h" 151 | 152 | #include "RemoteXYStream_Stream.h" // any stream 153 | #include "RemoteXYStream_HardSerial.h" 154 | #include "RemoteXYStream_SoftSerial.h" // need SoftwareSerial.h or SoftSerial.h 155 | #include "RemoteXYStream_USBSerial.h" 156 | #include "RemoteXYStream_AltSoftSerial.h" // need AltSoftSerial.h 157 | #include "RemoteXYStream_BluetoothSerial.h" // need BluetoothSerial.h 158 | #include "RemoteXYStream_BLEDevice.h" // need BLEDevice.h 159 | #include "RemoteXYStream_BLEPeripheral.h" // need BLEPeripheral.h 160 | #include "RemoteXYStream_ArduinoBLE.h" // need ArduinoBLEl.h 161 | #include "RemoteXYComm_WiFi.h" // need ESP8266WiFi.h (ESP8266) or WiFi.h (ESP32) or WiFi.h (Arduino shield) 162 | #include "RemoteXYComm_Ethernet.h" // need Ethernet.h 163 | #include "RemoteXYComm_ESP8266.h" 164 | 165 | 166 | #ifndef REMOTEXY_ACCESS_PASSWORD 167 | #define REMOTEXY_ACCESS_PASSWORD "" 168 | #endif 169 | 170 | 171 | #define RemoteXY_Handler() remotexy->handler () 172 | #define RemoteXY_CONF const PROGMEM RemoteXY_CONF_PROGMEM 173 | 174 | // predefined configurations 175 | 176 | #if defined(REMOTEXY_MODE__HARDSERIAL) || defined(REMOTEXY_MODE__SERIAL) || defined(REMOTEXY_MODE__HC05_HARDSERIAL) 177 | CRemoteXY *remotexy; 178 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYStream_HardSerial (&REMOTEXY_SERIAL, REMOTEXY_SERIAL_SPEED), REMOTEXY_ACCESS_PASSWORD) 179 | 180 | #elif defined(REMOTEXY_MODE__SOFTSERIAL) || defined(REMOTEXY_MODE__SOFTWARESERIAL) || defined(REMOTEXY_MODE__HC05_SOFTSERIAL) 181 | CRemoteXY *remotexy; 182 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYStream_SoftSerial (REMOTEXY_SERIAL_RX, REMOTEXY_SERIAL_TX, REMOTEXY_SERIAL_SPEED), REMOTEXY_ACCESS_PASSWORD) 183 | 184 | #elif defined(REMOTEXY_MODE__USBSERIAL) || defined(REMOTEXY_MODE__CDCSERIAL) 185 | CRemoteXY *remotexy; 186 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYStream_USBSerial (&REMOTEXY_SERIAL, REMOTEXY_SERIAL_SPEED), REMOTEXY_ACCESS_PASSWORD) 187 | 188 | #elif defined(REMOTEXY_MODE__ALTSOFTSERIAL) 189 | CRemoteXY *remotexy; 190 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYStream_AltSoftSerial (REMOTEXY_SERIAL_SPEED), REMOTEXY_ACCESS_PASSWORD) 191 | 192 | #elif defined(REMOTEXY_MODE__ESP32CORE_BLE) 193 | CRemoteXY *remotexy; 194 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYStream_BLEDevice (REMOTEXY_BLUETOOTH_NAME), REMOTEXY_ACCESS_PASSWORD) 195 | 196 | #elif defined(REMOTEXY_MODE__WIFI) || defined(REMOTEXY_MODE__ESP32CORE_WIFI) || defined(REMOTEXY_MODE__ESP8266CORE_ESP8266WIFI) || defined(REMOTEXY_MODE__ESP8266WIFI_LIB) 197 | CRemoteXY *remotexy; 198 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionServer (new CRemoteXYComm_WiFi (REMOTEXY_WIFI_SSID, REMOTEXY_WIFI_PASSWORD), REMOTEXY_SERVER_PORT), REMOTEXY_ACCESS_PASSWORD) 199 | 200 | #elif defined(REMOTEXY_MODE__WIFI_POINT) || defined(REMOTEXY_MODE__ESP32CORE_WIFI_POINT) || defined(REMOTEXY_MODE__ESP8266CORE_ESP8266WIFI_POINT) || defined(REMOTEXY_MODE__ESP8266WIFI_LIB_POINT) || defined(REMOTEXY_MODE__ESP8266WIFIPOINT_LIB) 201 | CRemoteXY *remotexy; 202 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionServer (new CRemoteXYComm_WiFiPoint (REMOTEXY_WIFI_SSID, REMOTEXY_WIFI_PASSWORD), REMOTEXY_SERVER_PORT), REMOTEXY_ACCESS_PASSWORD) 203 | 204 | #elif defined(REMOTEXY_MODE__WIFI_CLOUD) || defined(REMOTEXY_MODE__ESP32CORE_WIFI_CLOUD) || defined(REMOTEXY_MODE__ESP8266CORE_ESP8266WIFI_CLOUD) || defined(REMOTEXY_MODE__ESP8266WIFI_LIB_CLOUD) 205 | CRemoteXY *remotexy; 206 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionCloud (new CRemoteXYComm_WiFi (REMOTEXY_WIFI_SSID, REMOTEXY_WIFI_PASSWORD), REMOTEXY_CLOUD_SERVER, REMOTEXY_CLOUD_PORT, REMOTEXY_CLOUD_TOKEN), REMOTEXY_ACCESS_PASSWORD) 207 | 208 | #elif defined(REMOTEXY_MODE__HARDSERIAL_ESP8266_POINT) || defined(REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT) || defined(REMOTEXY_MODE__ESP8266POINT_HARDSERIAL) 209 | CRemoteXY *remotexy; 210 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionServer (new CRemoteXYComm_ESP8266Point (new CRemoteXYStream_HardSerial (&REMOTEXY_SERIAL, REMOTEXY_SERIAL_SPEED), REMOTEXY_WIFI_SSID, REMOTEXY_WIFI_PASSWORD), REMOTEXY_SERVER_PORT), REMOTEXY_ACCESS_PASSWORD) 211 | 212 | #elif defined(REMOTEXY_MODE__SOFTSERIAL_ESP8266_POINT) || defined(REMOTEXY_MODE__ESP8266_SOFTSERIAL_POINT) || defined(REMOTEXY_MODE__ESP8266POINT_SOFTSERIAL) 213 | CRemoteXY *remotexy; 214 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionServer (new CRemoteXYComm_ESP8266Point (new CRemoteXYStream_SoftSerial (REMOTEXY_SERIAL_RX, REMOTEXY_SERIAL_TX, REMOTEXY_SERIAL_SPEED), REMOTEXY_WIFI_SSID, REMOTEXY_WIFI_PASSWORD), REMOTEXY_SERVER_PORT), REMOTEXY_ACCESS_PASSWORD) 215 | 216 | #elif defined(REMOTEXY_MODE__ALTSOFTSERIAL_ESP8266_POINT) || defined(REMOTEXY_MODE__ESP8266_ALTSOFTSERIAL_POINT) 217 | CRemoteXY *remotexy; 218 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionServer (new CRemoteXYComm_ESP8266Point (new CRemoteXYStream_AltSoftSerial (REMOTEXY_SERIAL_SPEED), REMOTEXY_WIFI_SSID, REMOTEXY_WIFI_PASSWORD), REMOTEXY_SERVER_PORT), REMOTEXY_ACCESS_PASSWORD) 219 | 220 | #elif defined(REMOTEXY_MODE__HARDSERIAL_ESP8266) || defined(REMOTEXY_MODE__ESP8266_HARDSERIAL) 221 | CRemoteXY *remotexy; 222 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionServer (new CRemoteXYComm_ESP8266 (new CRemoteXYStream_HardSerial (&REMOTEXY_SERIAL, REMOTEXY_SERIAL_SPEED), REMOTEXY_WIFI_SSID, REMOTEXY_WIFI_PASSWORD), REMOTEXY_SERVER_PORT), REMOTEXY_ACCESS_PASSWORD) 223 | 224 | #elif defined(REMOTEXY_MODE__SOFTSERIAL_ESP8266) || defined(REMOTEXY_MODE__ESP8266_SOFTSERIAL) 225 | CRemoteXY *remotexy; 226 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionServer (new CRemoteXYComm_ESP8266 (new CRemoteXYStream_SoftSerial (REMOTEXY_SERIAL_RX, REMOTEXY_SERIAL_TX, REMOTEXY_SERIAL_SPEED), REMOTEXY_WIFI_SSID, REMOTEXY_WIFI_PASSWORD), REMOTEXY_SERVER_PORT), REMOTEXY_ACCESS_PASSWORD) 227 | 228 | #elif defined(REMOTEXY_MODE__ALTSOFTSERIAL_ESP8266) || defined(REMOTEXY_MODE__ESP8266_ALTSOFTSERIAL) 229 | CRemoteXY *remotexy; 230 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionServer (new CRemoteXYComm_ESP8266 (new CRemoteXYStream_AltSoftSerial (REMOTEXY_SERIAL_SPEED), REMOTEXY_WIFI_SSID, REMOTEXY_WIFI_PASSWORD), REMOTEXY_SERVER_PORT), REMOTEXY_ACCESS_PASSWORD) 231 | 232 | #elif defined(REMOTEXY_MODE__HARDSERIAL_ESP8266_CLOUD) || defined(REMOTEXY_MODE__ESP8266_HARDSERIAL_CLOUD) 233 | CRemoteXY *remotexy; 234 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionCloud (new CRemoteXYComm_ESP8266 (new CRemoteXYStream_HardSerial (&REMOTEXY_SERIAL, REMOTEXY_SERIAL_SPEED), REMOTEXY_WIFI_SSID, REMOTEXY_WIFI_PASSWORD), REMOTEXY_CLOUD_SERVER, REMOTEXY_CLOUD_PORT, REMOTEXY_CLOUD_TOKEN), REMOTEXY_ACCESS_PASSWORD) 235 | 236 | #elif defined(REMOTEXY_MODE__SOFTSERIAL_ESP8266_CLOUD) || defined(REMOTEXY_MODE__ESP8266_SOFTSERIAL_CLOUD) 237 | CRemoteXY *remotexy; 238 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionCloud (new CRemoteXYComm_ESP8266 (new CRemoteXYStream_SoftSerial (REMOTEXY_SERIAL_RX, REMOTEXY_SERIAL_TX, REMOTEXY_SERIAL_SPEED), REMOTEXY_WIFI_SSID, REMOTEXY_WIFI_PASSWORD), REMOTEXY_CLOUD_SERVER, REMOTEXY_CLOUD_PORT, REMOTEXY_CLOUD_TOKEN), REMOTEXY_ACCESS_PASSWORD) 239 | 240 | #elif defined(REMOTEXY_MODE__ALTSOFTSERIAL_ESP8266_CLOUD) || defined(REMOTEXY_MODE__ESP8266_ALTSOFTSERIAL_CLOUD) 241 | CRemoteXY *remotexy; 242 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionCloud (new CRemoteXYComm_ESP8266 (new CRemoteXYStream_AltSoftSerial (REMOTEXY_SERIAL_SPEED), REMOTEXY_WIFI_SSID, REMOTEXY_WIFI_PASSWORD), REMOTEXY_CLOUD_SERVER, REMOTEXY_CLOUD_PORT, REMOTEXY_CLOUD_TOKEN), REMOTEXY_ACCESS_PASSWORD) 243 | 244 | #elif defined(REMOTEXY_MODE__ETHERNET) || defined(REMOTEXY_MODE__ETHERNET_LIB) || defined(REMOTEXY_MODE__W5100_SPI) 245 | CRemoteXY *remotexy; 246 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionServer (new CRemoteXYComm_Ethernet (REMOTEXY_ETHERNET_MAC), REMOTEXY_SERVER_PORT), REMOTEXY_ACCESS_PASSWORD) 247 | 248 | #elif defined(REMOTEXY_MODE__ETHERNET_CLOUD) || defined(REMOTEXY_MODE__ETHERNET_LIB_CLOUD) 249 | CRemoteXY *remotexy; 250 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionCloud (new CRemoteXYComm_Ethernet (REMOTEXY_ETHERNET_MAC), REMOTEXY_CLOUD_SERVER, REMOTEXY_CLOUD_PORT, REMOTEXY_CLOUD_TOKEN), REMOTEXY_ACCESS_PASSWORD) 251 | 252 | #elif defined(REMOTEXY_MODE__ESP32CORE_BLUETOOTH) 253 | CRemoteXY *remotexy; 254 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYStream_BluetoothSerial (REMOTEXY_BLUETOOTH_NAME), REMOTEXY_ACCESS_PASSWORD) 255 | 256 | #elif defined(REMOTEXY_MODE__NRFCORE_BLEPERIPHERAL) 257 | CRemoteXY *remotexy; 258 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYStream_BLEPeripheral (REMOTEXY_BLUETOOTH_NAME), REMOTEXY_ACCESS_PASSWORD) 259 | 260 | #elif defined(REMOTEXY_MODE__ARDUINOBLE) 261 | CRemoteXY *remotexy; 262 | #define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYStream_ArduinoBLE (REMOTEXY_BLUETOOTH_NAME), REMOTEXY_ACCESS_PASSWORD) 263 | 264 | #endif 265 | 266 | //API 267 | #define RemoteXY_delay(ms) remotexy->delay (ms) 268 | #define RemoteXY_isConnected() remotexy->isConnected () 269 | 270 | 271 | #endif //_REMOTEXY_H_ 272 | 273 | -------------------------------------------------------------------------------- /src/RemoteXYApi.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYApi_h 2 | #define RemoteXYApi_h 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "RemoteXYDebugLog.h" 10 | #include "RemoteXYApiData.h" 11 | #include "RemoteXYConnection.h" 12 | #include "RemoteXYConnectionStream.h" 13 | #include "RemoteXYConnectionServer.h" 14 | #include "RemoteXYConnectionCloud.h" 15 | 16 | #include "RemoteXYComm.h" 17 | #include "RemoteXYCloudServer.h" 18 | #include "RemoteXYThread.h" 19 | #include "RemoteXYWire.h" 20 | #include "RemoteXYWireStream.h" 21 | #include "RemoteXYStream_Stream.h" 22 | 23 | #include "RemoteXYCloudServer.h" 24 | 25 | 26 | 27 | class CRemoteXY { 28 | public: 29 | CRemoteXYData data; 30 | 31 | 32 | public: 33 | CRemoteXY (const void * _conf, void * _var, const char * _accessPassword = NULL) { 34 | data.init (_conf, _var, _accessPassword); 35 | 36 | #if defined(REMOTEXY__DEBUGLOG) 37 | RemoteXYDebugLog.init (); 38 | RemoteXYDebugLog.write("RemoteXY started"); 39 | #endif 40 | } 41 | 42 | public: 43 | CRemoteXY (const void * _conf, void * _var, CRemoteXYConnectionComm * _conn, const char * _accessPassword = NULL) { 44 | data.init (_conf, _var, _accessPassword); 45 | addConnection (_conn); 46 | 47 | #if defined(REMOTEXY__DEBUGLOG) 48 | RemoteXYDebugLog.init (); 49 | RemoteXYDebugLog.write("RemoteXY started"); 50 | #endif 51 | } 52 | 53 | public: 54 | CRemoteXY (const void * _conf, void * _var, CRemoteXYStream * _comm, const char * _accessPassword = NULL) { 55 | data.init (_conf, _var, _accessPassword); 56 | addConnection (_comm); 57 | 58 | #if defined(REMOTEXY__DEBUGLOG) 59 | RemoteXYDebugLog.init (); 60 | RemoteXYDebugLog.write("RemoteXY started"); 61 | #endif 62 | } 63 | 64 | public: 65 | CRemoteXY (const void * _conf, void * _var, Stream * _stream, const char * _accessPassword = NULL) { 66 | data.init (_conf, _var, _accessPassword); 67 | addConnection (_stream); 68 | 69 | #if defined(REMOTEXY__DEBUGLOG) 70 | RemoteXYDebugLog.init (); 71 | RemoteXYDebugLog.write("RemoteXY started"); 72 | #endif 73 | } 74 | 75 | public: 76 | void setPassword (const char * _accessPassword) { 77 | data.setPassword (_accessPassword); 78 | } 79 | 80 | 81 | public: 82 | void addConnection (CRemoteXYConnectionComm * conn) { 83 | CRemoteXYComm * p = data.comms; 84 | while (p) { 85 | if (p == conn->comm) break; 86 | p = p->next; 87 | } 88 | if (!p) { 89 | conn->comm->next = data.comms; 90 | data.comms = conn->comm; 91 | } 92 | conn->next = data.connections; 93 | data.connections = conn; 94 | conn->init (&data); 95 | } 96 | 97 | public: 98 | void addConnection (CRemoteXYStream * comm) { 99 | CRemoteXYConnection * conn = new CRemoteXYConnectionStream (comm); 100 | conn->init (&data); 101 | } 102 | 103 | 104 | public: 105 | void addConnection (Stream * stream) { 106 | CRemoteXYStream_Stream * comm = new CRemoteXYStream_Stream (stream); 107 | CRemoteXYConnection * conn = new CRemoteXYConnectionStream (comm); 108 | conn->init (&data); 109 | } 110 | 111 | 112 | public: 113 | void handler () { 114 | uint8_t connect_flag = 0; 115 | 116 | // threads handler 117 | 118 | CRemoteXYThread * pt = data.threads; 119 | while (pt) { 120 | pt->handler (); 121 | connect_flag += pt->connect_flag; 122 | pt = pt->next; 123 | } 124 | *data.connect_flag = connect_flag; 125 | 126 | // communications handler 127 | 128 | CRemoteXYComm * comm = data.comms; 129 | while (comm) { 130 | comm->handler (); 131 | comm = comm->next; 132 | } 133 | 134 | // connections handler 135 | 136 | CRemoteXYConnectionComm * connection = data.connections; 137 | while (connection) { 138 | connection->handler (); 139 | connection = connection->next; 140 | } 141 | 142 | 143 | } 144 | 145 | 146 | 147 | 148 | 149 | /////////////////////////////////////////////////////////////////////////////// 150 | // API - PUBLIC DOCUMENTED FUNCTIONS 151 | 152 | public: 153 | void delay (uint32_t ms) { 154 | uint32_t t = millis (); 155 | while (true) { 156 | handler (); 157 | ::delay (1); // if does not use the delay it does not work on ESP8266 158 | if (millis () - t >= ms) break; 159 | } 160 | } 161 | 162 | 163 | public: 164 | uint8_t isConnected () { 165 | return *data.connect_flag; 166 | } 167 | 168 | 169 | }; 170 | 171 | 172 | 173 | 174 | 175 | #endif //RemoteXYApi_h 176 | 177 | -------------------------------------------------------------------------------- /src/RemoteXYApiData.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYApiData_h 2 | #define RemoteXYApiData_h 3 | 4 | #include 5 | 6 | 7 | #define REMOTEXY_PASSWORD_LENGTH_MAX 26 8 | 9 | class CRemoteXYThread; 10 | class CRemoteXYComm; 11 | class CRemoteXYConnectionComm; 12 | 13 | 14 | class CRemoteXYData { 15 | 16 | public: 17 | uint8_t confVersion; 18 | uint8_t *conf; 19 | uint8_t *var; 20 | uint8_t *accessPassword; 21 | uint16_t outputLength; 22 | uint16_t inputLength; 23 | uint16_t confLength; 24 | uint8_t *connect_flag; 25 | 26 | 27 | CRemoteXYThread * threads; 28 | CRemoteXYComm * comms; 29 | CRemoteXYConnectionComm * connections; 30 | 31 | 32 | public: 33 | void init (const void * _conf, void * _var, const char * _accessPassword = NULL) { 34 | 35 | uint8_t* p = (uint8_t*)_conf; 36 | uint8_t b = getConfByte (p++); 37 | 38 | if (b==0xff) { 39 | inputLength = getConfByte (p++); 40 | inputLength |= getConfByte (p++)<<8; 41 | outputLength = getConfByte (p++); 42 | outputLength |= getConfByte (p++)<<8; 43 | } 44 | else { 45 | inputLength = b; 46 | outputLength = getConfByte (p++); 47 | } 48 | confLength = getConfByte (p++); 49 | confLength |= getConfByte (p++)<<8; 50 | conf = p; 51 | confVersion = getConfByte (p); 52 | var = (uint8_t*)_var; 53 | uint16_t varLength = outputLength + inputLength; 54 | connect_flag = var + varLength; 55 | *connect_flag = 0; 56 | 57 | setPassword (_accessPassword); 58 | 59 | p = var; 60 | uint16_t i = varLength; 61 | while (i--) *p++=0; 62 | 63 | 64 | comms = NULL; 65 | connections = NULL; 66 | threads = NULL; 67 | } 68 | 69 | public: 70 | void setPassword (const char * _accessPassword) { 71 | accessPassword = NULL; 72 | if (_accessPassword != NULL) { 73 | accessPassword = (uint8_t*)_accessPassword; 74 | } 75 | } 76 | 77 | public: 78 | uint16_t getReceiveBufferSize () { 79 | uint16_t receiveBufferSize = inputLength; 80 | if (accessPassword != NULL) { 81 | if (receiveBufferSize < REMOTEXY_PASSWORD_LENGTH_MAX) receiveBufferSize = REMOTEXY_PASSWORD_LENGTH_MAX; 82 | } 83 | receiveBufferSize +=6; 84 | return receiveBufferSize; 85 | } 86 | 87 | public: 88 | inline uint8_t getConfByte (uint8_t* p) { 89 | return pgm_read_byte_near (p); 90 | } 91 | 92 | 93 | }; 94 | 95 | 96 | 97 | 98 | #endif //RemoteXYData_h -------------------------------------------------------------------------------- /src/RemoteXYCloudServer.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYCloudServer_h 2 | #define RemoteXYCloudServer_h 3 | 4 | 5 | #include "RemoteXYApiData.h" 6 | #include "RemoteXYComm.h" 7 | #include "RemoteXYWire.h" 8 | #include "RemoteXYWireStream.h" 9 | #include "RemoteXYWireCloud.h" 10 | 11 | #define REMOTEXY_CLOUD_CONNECT_TIMEOUT 10000 12 | #define REMOTEXY_CLOUD_ECHO_TIMEOUT 30000 13 | 14 | 15 | class CRemoteXYCloudClientAvailableListener { 16 | public: 17 | virtual void clientAvailable (CRemoteXYWireCloud * wire) = 0; 18 | }; 19 | 20 | 21 | class CRemoteXYCloudServer : public CRemoteXYReceivePackageListener, CRemoteXYSendPackageListener { 22 | public: 23 | CRemoteXYWireStream * wire; 24 | CRemoteXYWireCloud * cloudWires; 25 | 26 | private: 27 | CRemoteXYCloudClientAvailableListener * clientAvailableListener; 28 | 29 | uint8_t cloudRegistPackage[38]; 30 | enum { Registring, Working, Stopped } state; 31 | uint32_t timeOut; 32 | 33 | 34 | public: 35 | CRemoteXYCloudServer (CRemoteXYData * data, const char * _cloudToken, CRemoteXYCloudClientAvailableListener * listener) { 36 | 37 | 38 | uint8_t i; 39 | uint8_t *p = cloudRegistPackage; 40 | *p++ = data->getConfByte(data->conf+0); 41 | *p++ = 0; 42 | for (i=0; i<32; i++) { 43 | if (*_cloudToken==0) *(p++)=0; 44 | else *(p++)=*(_cloudToken++); 45 | } 46 | uint16_t *len = (uint16_t*)p; 47 | *len = data->outputLength + data->inputLength; 48 | if (data->confLength>*len) *len = data->confLength; 49 | *len += 6+1; 50 | len = (uint16_t*)(p+2); 51 | *len = data->getReceiveBufferSize (); 52 | #if REMOTEXY_MAX_CLIENTS == 1 53 | wire = new CRemoteXYWireStream (data); 54 | #else 55 | wire = new CRemoteXYWireStream (data, 2); 56 | #endif 57 | cloudWires = NULL; 58 | state = Stopped; 59 | 60 | clientAvailableListener = listener; 61 | } 62 | 63 | 64 | public: 65 | void begin (CRemoteXYClient * client) { 66 | wire->begin(client); 67 | wire->setReceivePackageListener (this); 68 | state = Registring; 69 | wire->sendPackage (0x11, cloudRegistPackage, 38, 0); 70 | timeOut = millis (); 71 | } 72 | 73 | public: 74 | void stop () { 75 | if (state != Stopped) { 76 | wire->stop (); 77 | state = Stopped; 78 | #if defined(REMOTEXY__DEBUGLOG) 79 | RemoteXYDebugLog.write ("Cloud server stoped"); 80 | #endif 81 | } 82 | } 83 | 84 | public: 85 | uint8_t running () { 86 | if (state != Stopped) return 1; 87 | return 0; 88 | } 89 | 90 | 91 | public: 92 | void handler () { 93 | if (state != Stopped) { 94 | CRemoteXYClient * client = wire->getClient (); 95 | wire->handler (); 96 | if (!client->connected ()) stop (); 97 | if (wire->running ()) { 98 | 99 | if (state == Registring) { 100 | if (millis() - timeOut > REMOTEXY_CLOUD_CONNECT_TIMEOUT) stop (); 101 | } 102 | else if (state == Working) { 103 | if (millis() - timeOut > REMOTEXY_CLOUD_ECHO_TIMEOUT) { 104 | #if defined(REMOTEXY__DEBUGLOG) 105 | RemoteXYDebugLog.write("Cloud server timed out"); 106 | #endif 107 | stop (); 108 | } 109 | } 110 | } 111 | else stop (); 112 | } 113 | } 114 | 115 | public: 116 | void sendPackage (uint8_t command, uint8_t *buf, uint16_t length, uint8_t fromPgm) override { 117 | wire->sendPackage (command, buf, length, fromPgm); 118 | } 119 | 120 | 121 | public: 122 | void receivePackage (CRemoteXYPackage * package) override { 123 | timeOut = millis (); 124 | if (package->command == 0x10) { 125 | wire->sendPackage (0x10, 0, 0, 0); 126 | } 127 | else if (package->command == 0x11) { 128 | state = Working; 129 | #if defined(REMOTEXY__DEBUGLOG) 130 | RemoteXYDebugLog.write ("Cloud server registration successfully"); 131 | #endif 132 | } 133 | else { 134 | uint8_t id = (package->command & 0x0e)>>1; 135 | package->command &= 0xf1; 136 | 137 | CRemoteXYWireCloud * pw = cloudWires; 138 | while (pw) { 139 | if ((pw->running ()) && (pw->id == id)) { 140 | pw->receivePackage (package); 141 | return; 142 | } 143 | pw = pw->next; 144 | } 145 | pw = getFreeWireCloud (); 146 | pw->init (id); 147 | clientAvailableListener->clientAvailable (pw); 148 | pw->receivePackage (package); 149 | } 150 | } 151 | 152 | private: 153 | CRemoteXYWireCloud * getFreeWireCloud () { 154 | CRemoteXYWireCloud * pw = cloudWires; 155 | while (pw) { 156 | if (!pw->running ()) return pw; 157 | pw = pw->next; 158 | } 159 | pw = new CRemoteXYWireCloud (this); 160 | pw->next = cloudWires; 161 | cloudWires = pw; 162 | return pw; 163 | } 164 | }; 165 | 166 | 167 | 168 | #endif //RemoteXYCloudServer_h -------------------------------------------------------------------------------- /src/RemoteXYComm.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYComm_h 2 | #define RemoteXYComm_h 3 | 4 | #include 5 | #include "RemoteXYDebugLog.h" 6 | #include "RemoteXYStream.h" 7 | 8 | 9 | #define UNUSED(x) (void)(x) 10 | 11 | class CRemoteXYClientAvailableListener { 12 | public: 13 | virtual void clientAvailable () = 0; 14 | }; 15 | 16 | 17 | 18 | class CRemoteXYClient: public CRemoteXYStream { 19 | public: 20 | CRemoteXYClient * next; 21 | 22 | public: 23 | CRemoteXYClient (): CRemoteXYStream() { 24 | } 25 | 26 | public: 27 | virtual uint8_t connect (const char *host, uint16_t port) {UNUSED (host); UNUSED (port); return 0;}; 28 | virtual void stop () {}; 29 | virtual uint8_t connected () {return 1;}; 30 | virtual uint8_t equal (CRemoteXYClient * cl) {UNUSED (cl); return 0;} 31 | }; 32 | 33 | 34 | class CRemoteXYServer { 35 | 36 | private: 37 | CRemoteXYClientAvailableListener * clientAvailableListener; 38 | 39 | public: 40 | void setClientAvailabListener (CRemoteXYClientAvailableListener * listener) { 41 | clientAvailableListener = listener; 42 | } 43 | 44 | public: 45 | void notifyClientAvailableListener () { 46 | if (clientAvailableListener) clientAvailableListener->clientAvailable (); 47 | } 48 | 49 | 50 | public: 51 | virtual uint8_t begin () {return 0;} 52 | virtual void stop () {}; 53 | virtual uint8_t available (CRemoteXYClient * client) {UNUSED (client); return 0;} 54 | 55 | }; 56 | 57 | 58 | 59 | class CRemoteXYComm { 60 | public: 61 | CRemoteXYComm * next; 62 | 63 | public: 64 | CRemoteXYComm () { 65 | #if defined(REMOTEXY__DEBUGLOG) 66 | RemoteXYDebugLog.init (); 67 | #endif 68 | } 69 | 70 | public: 71 | virtual void handler () {}; 72 | virtual uint8_t configured () {return 1;}; 73 | virtual CRemoteXYServer * createServer (uint16_t _port) {UNUSED (_port); return NULL;} 74 | virtual CRemoteXYClient * newClient () {return NULL;} 75 | }; 76 | 77 | 78 | 79 | #endif //RemoteXYComm_h -------------------------------------------------------------------------------- /src/RemoteXYComm_AT.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYComm_AT_h 2 | #define RemoteXYComm_AT_h 3 | 4 | #include "RemoteXYDebugLog.h" 5 | #include "RemoteXYComm.h" 6 | #include "RemoteXYFunc.h" 7 | #include 8 | 9 | #define UNUSED(x) (void)(x) 10 | 11 | #define REMOTEXYCOMM_AT__RECEIVE_BUFFER_SIZE 32 // maximum response length 12 | 13 | #define REMOTEXYCOMM_AT__COMMAND_TIMEOUT 1000 14 | #define REMOTEXYCOMM_AT__SEND_TIMEOUT 5000 15 | #define REMOTEXYCOMM_AT__TEST_TIMEOUT 30000 16 | #define REMOTEXYCOMM_AT__CONNECT_TIMEOUT 20000 17 | #define REMOTEXYCOMM_AT__NO_CHANNEL 0xff 18 | 19 | 20 | #define AT_ID_BLOCKING 255 21 | #define AT_ID_FINDMODULE 254 22 | #define AT_ID_TESTMODULE 253 23 | 24 | #define AT_RESULT_OK 1 25 | #define AT_RESULT_TIMEOUT 2 26 | #define AT_RESULT_ERROR 3 27 | #define AT_RESULT_FAIL 4 28 | #define AT_RESULT_BUSY 5 29 | #define AT_RESULT_RESET 6 30 | #define AT_RESULT_SEND_READY 7 31 | #define AT_RESULT_SEND_OK 8 32 | #define AT_RESULT_SEND_FAIL 9 33 | #define AT_RESULT_MESSAGE 10 34 | 35 | // standards answers 36 | const char * AT_ANSWER_ERROR = "ERROR"; 37 | const char * AT_ANSWER_FAIL = "FAIL"; 38 | const char * AT_ANSWER_BUSY = "BUSY *"; 39 | const char * AT_ANSWER_OK = "OK"; 40 | const char * AT_ANSWER_SEND_OK = "SEND OK"; 41 | const char * AT_ANSWER_SEND_FAIL = "SEND FAIL"; 42 | const char * AT_MESSAGE_READY = "READY"; 43 | const char * AT_MESSAGE_AT = "AT"; 44 | const char * AT_MESSAGE_CONNECT = "?,CONNECT"; 45 | const char * AT_MESSAGE_CLOSED = "?,CLOSED"; 46 | const char * AT_MESSAGE_CONNECT_FAIL = "?,CONNECT FAIL"; 47 | const char * AT_MESSAGE_IPD = "+IPD,?,*:"; 48 | const char * AT_MESSAGE_CIPSEND = "AT+CIPSEND="; 49 | const char * AT_MESSAGE_CIPCLOSE = "AT+CIPCLOSE="; 50 | const char * AT_MESSAGE_CIPSTART = "AT+CIPSTART="; 51 | 52 | 53 | 54 | class CRemoteXYClient_AT; 55 | class CRemoteXYComm_AT; 56 | 57 | class CRemoteXYClient_AT_Proto : public CRemoteXYClient { 58 | public: 59 | CRemoteXYComm_AT * comm; 60 | uint8_t id; 61 | uint8_t _connected; 62 | CRemoteXYClient_AT_Proto * next; 63 | 64 | }; 65 | 66 | 67 | 68 | class CRemoteXYComm_AT : public CRemoteXYComm, public CRemoteXYReadByteListener { 69 | 70 | private: 71 | CRemoteXYStream * serial; 72 | 73 | public: 74 | CRemoteXYServer * server; 75 | CRemoteXYClient_AT_Proto * clients; 76 | 77 | 78 | protected: 79 | char receiveBuffer[REMOTEXYCOMM_AT__RECEIVE_BUFFER_SIZE]; 80 | uint8_t receiveBufferIndex; 81 | 82 | char * params[3]; 83 | uint8_t paramsLength[3]; 84 | 85 | uint32_t lastAnswerTime; 86 | 87 | 88 | uint16_t connectAvailable; 89 | uint16_t freeAvailable; 90 | 91 | 92 | 93 | uint32_t commandTimeOut; 94 | uint32_t commandDelay; 95 | uint8_t commandIdentifier; 96 | void (*commandListener)(uint8_t, uint8_t); 97 | volatile uint8_t commandResult; 98 | volatile uint8_t commandBlocking; 99 | uint8_t commandFlag; 100 | 101 | uint16_t ipdId; 102 | uint16_t ipdSize; 103 | CRemoteXYClient_AT_Proto * ipdClient; 104 | 105 | int8_t availableClientID; 106 | 107 | uint8_t findModuleTryCount; 108 | uint8_t haveEcho; 109 | 110 | uint16_t sendByteMax; 111 | uint16_t sendByteSize; 112 | uint16_t sendByteNext; 113 | 114 | uint8_t clientConnectingID; 115 | uint8_t detected; 116 | 117 | public: 118 | virtual void moduleReset () {}; 119 | virtual void moduleLost () {}; 120 | virtual void moduleFound () {}; 121 | virtual uint8_t handleATMessage () {return 0;}; 122 | virtual void commandATListener (uint8_t identifier, uint8_t result) { UNUSED(identifier); UNUSED(result);}; 123 | 124 | 125 | 126 | 127 | 128 | public: 129 | CRemoteXYComm_AT (CRemoteXYStream *_serial, uint16_t _sendByteMax) : CRemoteXYComm () { 130 | serial = _serial; 131 | serial->setReadByteListener (this); 132 | sendByteMax = _sendByteMax; 133 | receiveBufferIndex=0; 134 | 135 | ipdSize = 0; 136 | lastAnswerTime = millis (); 137 | 138 | server = NULL; 139 | clients = NULL; 140 | availableClientID = -1; 141 | clientConnectingID = REMOTEXYCOMM_AT__NO_CHANNEL; 142 | detected = 0; // ??? 143 | 144 | 145 | commandDelay = 0; 146 | commandIdentifier = 0; 147 | commandListener = NULL; 148 | findModuleTryCount = 0; 149 | commandBlocking = 0; 150 | } 151 | 152 | 153 | 154 | private: 155 | void resultATcommand (uint8_t identifier, uint8_t result) { 156 | uint8_t id = identifier; 157 | if (result !=AT_RESULT_MESSAGE) { 158 | commandResult = result; 159 | commandDelay = 0; 160 | commandIdentifier = 0; 161 | } 162 | 163 | if (id == AT_ID_FINDMODULE) { 164 | if (result == AT_RESULT_OK) { 165 | findModuleTryCount = 0; 166 | moduleFound (); 167 | } 168 | } 169 | else if (id == AT_ID_TESTMODULE) { 170 | if (result == AT_RESULT_MESSAGE) { 171 | if (strcmpReceiveBuffer (AT_MESSAGE_AT)==0) haveEcho = 1; 172 | } 173 | else if (result == AT_RESULT_OK) { 174 | if (haveEcho) moduleLost (); 175 | 176 | } 177 | else moduleLost (); 178 | } 179 | else { 180 | commandATListener (id, result); 181 | if (commandListener) commandListener (id, result); 182 | } 183 | } 184 | 185 | 186 | private: 187 | void serialWrite (const char *p) { 188 | while (*p) { 189 | serial->write (*p++); 190 | } 191 | } 192 | 193 | 194 | public: 195 | uint8_t readyATCommand () { 196 | if ((commandIdentifier) || (ipdSize) || (commandBlocking)) return 0; 197 | return 1; 198 | } 199 | 200 | public: 201 | void setATCommandListener (void (*listener)(uint8_t, uint8_t)) { 202 | commandListener = listener; 203 | } 204 | 205 | public: 206 | void setATTimeOut (uint32_t timeOut) { 207 | commandDelay = timeOut; 208 | } 209 | 210 | public: 211 | uint8_t getATResult () { 212 | return commandResult; 213 | } 214 | 215 | 216 | private: 217 | void sendArgPtr (const char * p, va_list *argptr) { 218 | if (p) { 219 | while (p) { 220 | serialWrite (p); 221 | #if defined(REMOTEXY__DEBUGLOG) 222 | RemoteXYDebugLog.writeOutput (p); 223 | #endif 224 | p=va_arg(*argptr,char*); 225 | } 226 | serialWrite ("\r\n"); 227 | #if defined(REMOTEXY__DEBUGLOG) 228 | RemoteXYDebugLog.writeInputNewString (); 229 | #endif 230 | } 231 | commandTimeOut = millis(); 232 | if (commandDelay == 0) commandDelay = REMOTEXYCOMM_AT__COMMAND_TIMEOUT; 233 | commandResult = 0; 234 | } 235 | 236 | // not blocking funktion, use: 237 | // for children class - virtual commandATListener (identifier, result) 238 | // for static function - setATListener (func) 239 | // result: 240 | // 0 - command did not send 241 | // 1 - command sent 242 | public: 243 | uint8_t sendATCommand (uint8_t identifier, const char * command, ...) { 244 | if (!readyATCommand ()) { 245 | commandDelay = 0; 246 | return 0; 247 | } 248 | va_list argptr; 249 | va_start (argptr, command); 250 | sendArgPtr (command, &argptr); 251 | va_end(argptr); 252 | commandIdentifier = identifier; 253 | return 1; 254 | } 255 | 256 | 257 | // blocking funktion 258 | // result: AT_RESULT_XXXXX 259 | public: 260 | uint8_t sendATCommandForResult (const char * command, ...) { 261 | if (!readyATCommand ()) { 262 | commandDelay = 0; 263 | return AT_RESULT_BUSY; 264 | } 265 | va_list argptr; 266 | va_start (argptr, command); 267 | sendArgPtr (command, &argptr); 268 | va_end(argptr); 269 | 270 | commandIdentifier = AT_ID_BLOCKING; 271 | commandBlocking = 1; 272 | while (commandResult == 0) { 273 | if (millis() - commandTimeOut > commandDelay) { 274 | resultATcommand (commandIdentifier, AT_RESULT_TIMEOUT); 275 | } 276 | else serial->handler (); 277 | } 278 | commandBlocking = 0; 279 | return commandResult; 280 | } 281 | 282 | 283 | public: 284 | uint8_t waitATResult () { 285 | return sendATCommandForResult (NULL, NULL); 286 | } 287 | 288 | 289 | public: 290 | void readByte (uint8_t byte) override { 291 | 292 | if (ipdSize) { 293 | ipdSize--; 294 | if (ipdClient) { 295 | ipdClient->notifyReadByteListener (byte); 296 | } 297 | #if defined(REMOTEXY__DEBUGLOG) 298 | if (ipdSize == 0) RemoteXYDebugLog.writeInputNewString (); 299 | #endif 300 | return; 301 | } 302 | 303 | if (byte==10) return; 304 | #if defined(REMOTEXY__DEBUGLOG) 305 | if (byte==13) RemoteXYDebugLog.writeInputNewString (); 306 | else RemoteXYDebugLog.writeInputChar (byte); 307 | #endif 308 | if (byte==13) { 309 | lastAnswerTime = millis (); 310 | receiveBuffer[receiveBufferIndex]=0; 311 | if (receiveBufferIndex == 0) return; 312 | receiveBufferIndex=0; 313 | 314 | if (strcmpReceiveBuffer (AT_MESSAGE_CONNECT)==0) { // new client 315 | uint8_t id = getATParamInt(0); 316 | if (id != clientConnectingID) { 317 | availableClientID = id; 318 | if (server) server->notifyClientAvailableListener (); 319 | } 320 | return; 321 | } 322 | if (strcmpReceiveBuffer (AT_MESSAGE_CLOSED)==0) { clientClosed (); return; } // client closed 323 | if (strcmpReceiveBuffer (AT_MESSAGE_CONNECT_FAIL)==0) { clientClosed (); return; } // client closed 324 | if (strcmpReceiveBuffer (AT_MESSAGE_READY)==0) { 325 | if (commandIdentifier) resultATcommand (commandIdentifier, AT_RESULT_TIMEOUT); 326 | moduleReset (); 327 | return; 328 | } 329 | if (handleATMessage ()) return; 330 | if (commandIdentifier) { 331 | if (strcmpReceiveBuffer (AT_ANSWER_OK)==0) resultATcommand (commandIdentifier, AT_RESULT_OK); 332 | else if (strcmpReceiveBuffer (AT_ANSWER_SEND_OK)==0) resultATcommand (commandIdentifier, AT_RESULT_SEND_OK); 333 | else if (strcmpReceiveBuffer (AT_ANSWER_ERROR)==0) resultATcommand (commandIdentifier, AT_RESULT_ERROR); 334 | else if (strcmpReceiveBuffer (AT_ANSWER_FAIL)==0) resultATcommand (commandIdentifier, AT_RESULT_FAIL); 335 | else if (strcmpReceiveBuffer (AT_ANSWER_BUSY)==0) resultATcommand (commandIdentifier, AT_RESULT_BUSY); 336 | else if (strcmpReceiveBuffer (AT_ANSWER_SEND_FAIL)==0) resultATcommand (commandIdentifier, AT_RESULT_SEND_FAIL); 337 | else resultATcommand (commandIdentifier, AT_RESULT_MESSAGE); 338 | return; 339 | } 340 | } 341 | else { 342 | if ((byte>0x60) && (byte<=0x7a)) byte-=0x20; 343 | if (receiveBufferIndexid == ipdId) && (p->_connected)) break; 357 | p = p->next; 358 | } 359 | ipdClient = p; 360 | return; 361 | } 362 | } 363 | else if ((byte=='>') && (receiveBufferIndex==1)) { 364 | receiveBufferIndex = 0; 365 | resultATcommand (commandIdentifier, AT_RESULT_SEND_READY); 366 | } 367 | else if ((byte==' ') && (receiveBufferIndex==1)) { 368 | receiveBufferIndex = 0; 369 | } 370 | } 371 | } 372 | 373 | 374 | 375 | public: 376 | void handler () override { // override CRemoteXYComm 377 | 378 | serial->handler (); 379 | 380 | if (!ipdSize) { 381 | if (commandIdentifier) { 382 | if (millis() - commandTimeOut > commandDelay) { 383 | resultATcommand (commandIdentifier, AT_RESULT_TIMEOUT); 384 | } 385 | } 386 | else if (findModuleTryCount) { 387 | if (millis() - lastAnswerTime > REMOTEXYCOMM_AT__COMMAND_TIMEOUT) { 388 | findModuleTryCount--; 389 | if (findModuleTryCount == 0) { 390 | #if defined(REMOTEXY__DEBUGLOG) 391 | RemoteXYDebugLog.write ("Мodule does not respond to AT commands"); 392 | #endif 393 | findModuleTryCount = 10; 394 | } 395 | lastAnswerTime = millis (); 396 | sendATCommand (AT_ID_FINDMODULE, AT_MESSAGE_AT, NULL); 397 | } 398 | } 399 | else { 400 | if (millis() - lastAnswerTime > REMOTEXYCOMM_AT__TEST_TIMEOUT) { 401 | haveEcho = 0; 402 | if (sendATCommand (AT_ID_TESTMODULE, AT_MESSAGE_AT, NULL)) { 403 | lastAnswerTime = millis(); 404 | } 405 | } 406 | } 407 | } 408 | } 409 | 410 | 411 | private: 412 | void clientClosed () { 413 | uint8_t id = getATParamInt(0); 414 | if (availableClientID == id) availableClientID = -1; 415 | else { 416 | CRemoteXYClient_AT_Proto * p = clients; 417 | while (p) { 418 | if ((p->id == id) && (p->_connected)) { 419 | p->_connected = 0; 420 | //return; 421 | } 422 | p = p->next; 423 | } 424 | } 425 | } 426 | 427 | public: 428 | uint8_t server_available (CRemoteXYClient_AT_Proto * client) { 429 | if (availableClientID >= 0) { 430 | client->id = availableClientID; 431 | client->_connected = 1; 432 | availableClientID = -1; 433 | return 1; 434 | } 435 | return 0; 436 | } 437 | 438 | public: 439 | uint8_t client_connect (CRemoteXYClient_AT_Proto * client, const char *host, uint16_t port) { 440 | char sport[6]; 441 | char sid[2]; 442 | int8_t i; 443 | CRemoteXYClient_AT_Proto * p; 444 | if (client->_connected) client_stop (client); 445 | clientConnectingID = REMOTEXYCOMM_AT__NO_CHANNEL; 446 | for (i=3; i>=0; i--) { 447 | p = clients; 448 | while (p) { 449 | if ((p->_connected) && (client->id == i)) break; 450 | p=p->next; 451 | } 452 | if (!p) { 453 | clientConnectingID = i; 454 | break; 455 | } 456 | } 457 | if (clientConnectingID == REMOTEXYCOMM_AT__NO_CHANNEL) return 0; 458 | rxy_itos (port, sport); 459 | *sid=clientConnectingID+0x30; 460 | *(sid+1)=0; 461 | setATTimeOut (REMOTEXYCOMM_AT__CONNECT_TIMEOUT); 462 | uint8_t res = sendATCommandForResult (AT_MESSAGE_CIPSTART, sid, ",\"TCP\",\"", host,"\",", sport,NULL); 463 | i = clientConnectingID; 464 | clientConnectingID = REMOTEXYCOMM_AT__NO_CHANNEL; 465 | if (res != AT_RESULT_OK) return 0; 466 | client->id = i; 467 | client->_connected = 1; 468 | return 1; 469 | } 470 | 471 | public: 472 | void client_stop (CRemoteXYClient_AT_Proto * client) { 473 | if (client->_connected) { 474 | client->_connected = 0; 475 | char s[2]; 476 | *s=client->id+0x30; 477 | *(s+1) = 0; 478 | sendATCommandForResult (AT_MESSAGE_CIPCLOSE,s,NULL); 479 | } 480 | } 481 | 482 | public: 483 | void client_startWrite (CRemoteXYClient_AT_Proto * client, uint16_t size) { 484 | if (client->_connected) { 485 | char s[8]; 486 | sendByteSize = size; 487 | if (sendByteSize > sendByteMax) sendByteSize = sendByteMax; 488 | sendByteNext = size - sendByteSize; 489 | 490 | rxy_itos (sendByteSize, s+2); 491 | *s=client->id+0x30; 492 | *(s+1)=','; 493 | #if defined(REMOTEXY__DEBUGLOG) 494 | RemoteXYDebugLog.writeInputNewString (); 495 | #endif 496 | uint8_t res = sendATCommandForResult (AT_MESSAGE_CIPSEND,s,NULL); 497 | if (res == AT_RESULT_OK) res = waitATResult (); 498 | if (res == AT_RESULT_SEND_READY) { 499 | #if defined(REMOTEXY__DEBUGLOG) 500 | RemoteXYDebugLog.writeAdd (" *send "); 501 | RemoteXYDebugLog.writeAdd (sendByteSize); 502 | RemoteXYDebugLog.writeAdd (" bytes*"); 503 | #endif 504 | return; 505 | } 506 | sendByteSize = 0; 507 | } 508 | } 509 | 510 | public: 511 | void client_write (CRemoteXYClient_AT_Proto * client, uint8_t byte) { 512 | if (sendByteSize) { 513 | serial->write (byte); 514 | sendByteSize--; 515 | if (sendByteSize == 0) { 516 | setATTimeOut (REMOTEXYCOMM_AT__SEND_TIMEOUT); 517 | if (waitATResult () == AT_RESULT_SEND_OK) { 518 | if (sendByteNext) client_startWrite (client, sendByteNext); 519 | } 520 | } 521 | } 522 | } 523 | 524 | 525 | 526 | 527 | public: 528 | void findModule () { 529 | findModuleTryCount=10; 530 | lastAnswerTime = millis (); 531 | } 532 | 533 | 534 | protected: 535 | uint8_t strcmpReceiveBuffer (const char * temp) { 536 | uint8_t k = 0; 537 | char * str = receiveBuffer; 538 | while (*temp) { 539 | if (!*str) return 1; 540 | switch (*temp) { 541 | case '?': 542 | params[k]=str; 543 | paramsLength[k]=1; 544 | temp++; 545 | str++; 546 | k++; 547 | break; 548 | case '*': 549 | params[k]=str; 550 | paramsLength[k]=0; 551 | temp++; 552 | while (*str!=*temp) { 553 | if (!*str++) return 1; 554 | paramsLength[k]++; 555 | } 556 | k++; 557 | break; 558 | default: 559 | if (*(str++)!=*(temp++)) return 1; 560 | break; 561 | } 562 | } 563 | if (*str) return 1; 564 | return 0; 565 | } 566 | 567 | protected: 568 | uint16_t getATParamInt (uint8_t k) { 569 | uint16_t res = 0; 570 | char * p=params[k]; 571 | uint8_t i=paramsLength[k]; 572 | while (i--) res = res*10+(*p++)-'0'; 573 | return res; 574 | } 575 | 576 | public: 577 | void registerClient (CRemoteXYClient_AT_Proto * client) { 578 | client->next = clients; 579 | clients = client; 580 | } 581 | 582 | public: 583 | void removeClient (CRemoteXYClient_AT_Proto * client) { 584 | CRemoteXYClient_AT_Proto ** pclient = &clients; 585 | while (*pclient) { 586 | if (*pclient == client) { 587 | if ((*pclient)->_connected) client_stop (*pclient); 588 | *pclient = client->next; 589 | return; 590 | } 591 | pclient = &((*pclient)->next); 592 | } 593 | } 594 | 595 | 596 | }; 597 | 598 | 599 | class CRemoteXYServer_AT : public CRemoteXYServer { 600 | 601 | 602 | protected: 603 | CRemoteXYComm_AT * comm; 604 | uint16_t port; 605 | 606 | public: 607 | CRemoteXYServer_AT (CRemoteXYComm_AT * _comm, uint16_t _port) { 608 | comm = _comm; 609 | port = _port; 610 | comm->server = this; 611 | } 612 | 613 | ~CRemoteXYServer_AT () { 614 | if (comm) comm->server = NULL; 615 | } 616 | 617 | 618 | public: 619 | uint8_t available (CRemoteXYClient * client) override { 620 | return comm->server_available ((CRemoteXYClient_AT_Proto *)client); 621 | } 622 | 623 | uint8_t begin () override { 624 | char sport[6]; 625 | rxy_itos (port, sport); 626 | if (comm->sendATCommandForResult ("AT+CIPSERVER=1,", sport, NULL) != AT_RESULT_OK) return 0; 627 | if (comm->sendATCommandForResult ("AT+CIPSTO=30", NULL) != AT_RESULT_OK) return 0; 628 | return 1; 629 | } 630 | 631 | void stop () override { 632 | comm->sendATCommandForResult ("AT+CIPSERVER=0", NULL); 633 | } 634 | 635 | }; 636 | 637 | 638 | class CRemoteXYClient_AT : public CRemoteXYClient_AT_Proto { 639 | 640 | public: 641 | CRemoteXYClient_AT (CRemoteXYComm_AT * _comm) { 642 | comm = _comm; 643 | _connected = 0; 644 | comm->registerClient (this); 645 | } 646 | 647 | ~CRemoteXYClient_AT () { 648 | if (comm) comm->removeClient (this); 649 | } 650 | 651 | public: 652 | uint8_t connect (const char *host, uint16_t port) override { 653 | if (comm) return comm->client_connect (this, host, port); 654 | return 0; 655 | } 656 | 657 | public: 658 | uint8_t connected () override { 659 | return _connected; 660 | } 661 | 662 | public: 663 | void stop () override { 664 | if (comm) comm->client_stop (this); 665 | } 666 | 667 | void startWrite (uint16_t size) override { 668 | if (comm) comm->client_startWrite (this, size); 669 | } 670 | 671 | void write (uint8_t byte) override { 672 | if (comm) comm->client_write (this, byte); 673 | } 674 | 675 | }; 676 | 677 | 678 | 679 | 680 | 681 | #endif // RemoteXYComm_AT_h 682 | -------------------------------------------------------------------------------- /src/RemoteXYComm_ESP8266.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYComm_ESP8266_h 2 | #define RemoteXYComm_ESP8266_h 3 | 4 | #include "RemoteXYDebugLog.h" 5 | #include "RemoteXYComm_AT.h" 6 | 7 | #define REMOTEXYCOMM_ESP8266__SERVER_TIMEOUT 10000 8 | #define REMOTEXYCOMM_ESP8266__WIFICONNECT_TIMEOUT 30000 9 | 10 | #define REMOTEXYCOMM_ESP8266__ID_WIFICONNECT 1 11 | 12 | #define REMOTEXYCOMM_ESP8266__MAX_SEND_BYTE_SIZE 2048 13 | 14 | const char * AT_MESSAGE_WIFI_DISCONNECT = "WIFI DISCONNECT"; 15 | 16 | 17 | class CRemoteXYComm_ESP8266_Proto : public CRemoteXYComm_AT { 18 | 19 | protected: 20 | const char * wifiSsid; 21 | const char * wifiPassword; 22 | enum { Search, Reset, SearchAfterReset, Init, WaitWiFi, WaitReconnect, Configured } state; 23 | uint32_t timeOut; 24 | 25 | public: 26 | CRemoteXYComm_ESP8266_Proto (CRemoteXYStream *_serial, const char * _wifiSsid, const char * _wifiPassword) : CRemoteXYComm_AT (_serial, REMOTEXYCOMM_ESP8266__MAX_SEND_BYTE_SIZE) { 27 | wifiSsid = _wifiSsid; 28 | wifiPassword = _wifiPassword; 29 | state = Search; 30 | findModule (); 31 | } 32 | 33 | 34 | void moduleFound () override { 35 | if ((state == Reset) || (state == SearchAfterReset)) moduleReset (); 36 | else { 37 | state = Reset; 38 | timeOut = millis (); 39 | sendATCommandForResult ("AT+RST",NULL); // reset module 40 | } 41 | } 42 | 43 | protected: 44 | void moduleLost () override { 45 | state = Search; 46 | findModule (); 47 | } 48 | 49 | 50 | 51 | uint8_t configured () override { 52 | return (state == Configured); 53 | }; 54 | 55 | virtual CRemoteXYServer * createServer (uint16_t _port) override { 56 | if (!server) { 57 | server = new CRemoteXYServer_AT (this, _port); 58 | return server; 59 | } 60 | return NULL; 61 | } 62 | 63 | public: 64 | CRemoteXYClient * newClient () override { 65 | return new CRemoteXYClient_AT (this); 66 | } 67 | 68 | }; 69 | 70 | class CRemoteXYComm_ESP8266 : public CRemoteXYComm_ESP8266_Proto { 71 | 72 | public: 73 | CRemoteXYComm_ESP8266 (CRemoteXYStream *_serial, const char * _wifiSsid, const char * _wifiPassword) : CRemoteXYComm_ESP8266_Proto (_serial, _wifiSsid, _wifiPassword) { 74 | } 75 | 76 | protected: 77 | void moduleReset () override { 78 | if (!initModule ()) { 79 | state = Search; 80 | findModule (); 81 | } 82 | } 83 | 84 | 85 | 86 | private: 87 | uint8_t initModule () { 88 | state = Init; 89 | if (sendATCommandForResult ("ATE0",NULL) != AT_RESULT_OK) return 0; 90 | if (sendATCommandForResult ("AT+CWMODE=1",NULL) != AT_RESULT_OK) return 0; 91 | if (sendATCommandForResult ("AT+CWQAP",NULL) != AT_RESULT_OK) return 0; 92 | if (sendATCommandForResult ("AT+CWDHCP=1,1",NULL) != AT_RESULT_OK) return 0; 93 | if (sendATCommandForResult ("AT+CIPMODE=0",NULL) != AT_RESULT_OK) return 0; 94 | if (sendATCommandForResult ("AT+CIPMUX=1",NULL) != AT_RESULT_OK) return 0; 95 | beginWiFi (); 96 | return 1; 97 | } 98 | 99 | private: 100 | void beginWiFi () { 101 | state = Init; 102 | setATTimeOut (REMOTEXYCOMM_ESP8266__WIFICONNECT_TIMEOUT); 103 | if (sendATCommand (REMOTEXYCOMM_ESP8266__ID_WIFICONNECT, "AT+CWJAP=\"",wifiSsid,"\",\"",wifiPassword,"\"",NULL)) state = WaitWiFi; 104 | } 105 | 106 | 107 | protected: 108 | void commandATListener (uint8_t identifier, uint8_t result) override { 109 | if (identifier == REMOTEXYCOMM_ESP8266__ID_WIFICONNECT) { 110 | if (result == AT_RESULT_OK) { 111 | #if defined(REMOTEXY__DEBUGLOG) 112 | sendATCommandForResult ("AT+CIPSTA?",NULL); 113 | #endif 114 | state = Configured; 115 | } 116 | else { 117 | state = WaitReconnect; 118 | timeOut = millis(); 119 | } 120 | } 121 | } 122 | 123 | virtual void handler () override { // override CRemoteXYComm_AT 124 | CRemoteXYComm_AT::handler (); 125 | if (state == Reset) { 126 | if (millis() - timeOut > 5000) { 127 | state = SearchAfterReset; 128 | findModule (); 129 | } 130 | } 131 | else if (state == Init) beginWiFi (); 132 | else if (state == WaitReconnect) { 133 | if (millis() - timeOut > REMOTEXYCOMM_ESP8266__WIFICONNECT_TIMEOUT) beginWiFi (); 134 | } 135 | } 136 | 137 | uint8_t handleATMessage () override { // override CRemoteXYComm_AT 138 | if (strcmpReceiveBuffer (AT_MESSAGE_WIFI_DISCONNECT)==0) { 139 | if (state == Configured) state = Init; 140 | return 1; 141 | } 142 | return 0; 143 | } 144 | 145 | 146 | }; 147 | 148 | 149 | class CRemoteXYComm_ESP8266Point : public CRemoteXYComm_ESP8266_Proto { 150 | 151 | public: 152 | CRemoteXYComm_ESP8266Point (CRemoteXYStream *_serial, const char * _wifiSsid, const char * _wifiPassword) : CRemoteXYComm_ESP8266_Proto (_serial, _wifiSsid, _wifiPassword) { 153 | } 154 | 155 | protected: 156 | void moduleReset () override { 157 | initModule (); 158 | if (state != Configured) { 159 | state = Search; 160 | findModule (); 161 | } 162 | } 163 | 164 | private: 165 | void initModule () { 166 | state = Init; 167 | if (sendATCommandForResult ("ATE0",NULL) != AT_RESULT_OK) return; 168 | if (sendATCommandForResult ("AT+CWMODE=2",NULL) != AT_RESULT_OK) return; 169 | if (sendATCommandForResult ("AT+CWDHCP=0,1",NULL) != AT_RESULT_OK) return; 170 | 171 | char crypt[2] = {*wifiPassword?'4':'0',0}; 172 | setATTimeOut (5000); 173 | if (sendATCommandForResult ("AT+CWSAP=\"",wifiSsid,"\",\"",wifiPassword,"\",10,",crypt,NULL) != AT_RESULT_OK) return; 174 | if (sendATCommandForResult ("AT+CIPMODE=0",NULL) != AT_RESULT_OK) return; 175 | if (sendATCommandForResult ("AT+CIPMUX=1",NULL) != AT_RESULT_OK) return; 176 | state = Configured; 177 | } 178 | 179 | virtual void handler () override { 180 | CRemoteXYComm_AT::handler (); 181 | if (state == Reset) { 182 | if (millis() - timeOut > 5000) { 183 | state = SearchAfterReset; 184 | findModule (); 185 | } 186 | } 187 | } 188 | 189 | }; 190 | 191 | 192 | 193 | 194 | #endif // RemoteXYComm_ESP8266_h 195 | -------------------------------------------------------------------------------- /src/RemoteXYComm_Ethernet.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYComm_Ethernet_h 2 | #define RemoteXYComm_Ethernet_h 3 | 4 | 5 | #if defined (ethernet_h_) 6 | 7 | #include "RemoteXYDebugLog.h" 8 | #include "RemoteXYComm.h" 9 | #include "RemoteXYFunc.h" 10 | 11 | 12 | #define REMOREXYCOMM_ETHERNET__SEND_BUFFER_SIZE 32 13 | 14 | class CRemoteXYClient_Ethernet : public CRemoteXYClient { 15 | public: 16 | EthernetClient client; 17 | 18 | uint8_t sendBuffer[REMOREXYCOMM_ETHERNET__SEND_BUFFER_SIZE]; 19 | uint16_t sendBufferCount; 20 | uint16_t sendBytesAvailable; 21 | 22 | public: 23 | uint8_t connect (const char *host, uint16_t port) override { 24 | return client.connect(host, port); 25 | }; 26 | 27 | public: 28 | uint8_t connected () override { 29 | return client.connected(); 30 | }; 31 | 32 | public: 33 | void stop () override { 34 | client.stop (); 35 | }; 36 | 37 | public: 38 | void handler () override { 39 | while (client.available ()) notifyReadByteListener (client.read ()); 40 | } 41 | 42 | 43 | 44 | public: 45 | void startWrite (uint16_t len) override { 46 | sendBytesAvailable = len; 47 | sendBufferCount = 0; 48 | } 49 | 50 | public: 51 | void write (uint8_t b) override { 52 | sendBuffer[sendBufferCount++] = b; 53 | sendBytesAvailable--; 54 | if ((sendBufferCount == REMOREXYCOMM_ETHERNET__SEND_BUFFER_SIZE) || (sendBytesAvailable==0)) { 55 | client.write (sendBuffer, sendBufferCount); 56 | sendBufferCount=0; 57 | } 58 | } 59 | 60 | 61 | }; 62 | 63 | #if defined (ESP32) 64 | class EthernetServerESP32: public EthernetServer { 65 | public: 66 | EthernetServerESP32 (uint16_t port) : EthernetServer (port) {} 67 | void begin(uint16_t port=0) {} 68 | }; 69 | #endif 70 | 71 | class CRemoteXYServer_Ethernet : public CRemoteXYServer { 72 | private: 73 | EthernetServer * server; 74 | uint8_t soketConnectArr[MAX_SOCK_NUM]; 75 | 76 | public: 77 | CRemoteXYServer_Ethernet (uint16_t _port) { 78 | #if defined (ESP32) 79 | server = new EthernetServerESP32 (_port); 80 | #else 81 | server = new EthernetServer (_port); 82 | #endif 83 | for (uint8_t i = 0; i < MAX_SOCK_NUM; i++) soketConnectArr[i] = 0; 84 | } 85 | 86 | 87 | public: 88 | virtual uint8_t begin () override { 89 | server->begin (); 90 | return 1; 91 | } 92 | 93 | 94 | uint8_t available (CRemoteXYClient * client) override { 95 | EthernetClient cl; 96 | uint8_t i; 97 | for (i = 0; i < MAX_SOCK_NUM; i++) { 98 | cl = EthernetClient (i); 99 | if (!cl.connected ()) soketConnectArr[i] = 0; 100 | } 101 | cl = server->available (); 102 | if (cl.connected ()) { 103 | i = cl.getSocketNumber(); 104 | if (iclient = cl; 108 | return 1; 109 | } 110 | } 111 | } 112 | return 0; 113 | } 114 | 115 | }; 116 | 117 | 118 | class CRemoteXYComm_Ethernet : public CRemoteXYComm { 119 | 120 | private: 121 | uint8_t mac[6]; 122 | enum {NoHardware, LinkDetecting, Work} state; 123 | uint32_t timeout; 124 | 125 | 126 | public: 127 | CRemoteXYComm_Ethernet (const char * macAddress) : CRemoteXYComm () { 128 | rxy_getMacAddr (macAddress, mac); 129 | 130 | #if defined(REMOTEXY__DEBUGLOG) 131 | RemoteXYDebugLog.write("Ethernet begin ..."); 132 | #endif 133 | 134 | Ethernet.begin(mac, 1000); 135 | 136 | if (Ethernet.hardwareStatus() == EthernetNoHardware) { 137 | state = NoHardware; 138 | #if defined(REMOTEXY__DEBUGLOG) 139 | RemoteXYDebugLog.write("Ethernet module was not found"); 140 | #endif 141 | } 142 | else { 143 | state = LinkDetecting; 144 | #if defined(REMOTEXY__DEBUGLOG) 145 | if (!linkON ()) { 146 | RemoteXYDebugLog.write("Ethernet link OFF"); 147 | } 148 | #endif 149 | } 150 | timeout = millis (); 151 | } 152 | 153 | 154 | private: 155 | uint8_t linkON () { 156 | if (uint32_t(Ethernet.localIP()) != 0) return 1; 157 | /* 158 | if (Ethernet.hardwareStatus () == EthernetW5100) { 159 | if (uint32_t(Ethernet.localIP()) != 0) return 1; 160 | } 161 | else { 162 | if (Ethernet.linkStatus () == LinkON) return 1; 163 | } 164 | */ 165 | return 0; 166 | } 167 | 168 | 169 | public: 170 | void handler () override { 171 | 172 | if (state == NoHardware) return; 173 | 174 | if (linkON ()) { 175 | if (state == LinkDetecting) { 176 | #if defined(REMOTEXY__DEBUGLOG) 177 | RemoteXYDebugLog.write ("Ethernet link ON"); 178 | RemoteXYDebugLog.write("IP: "); 179 | RemoteXYDebugLog.serial->print(Ethernet.localIP()); 180 | #endif 181 | state = Work; 182 | } 183 | timeout = millis (); 184 | } 185 | else { // LinkOFF 186 | if (state == Work) { 187 | state = LinkDetecting; 188 | #if defined(REMOTEXY__DEBUGLOG) 189 | RemoteXYDebugLog.write ("Ethernet link OFF"); 190 | #endif 191 | } 192 | else { 193 | if (millis () - timeout > 5000) { 194 | Ethernet.begin(mac, 100); 195 | timeout = millis (); 196 | } 197 | } 198 | } 199 | } 200 | 201 | 202 | public: 203 | uint8_t configured () override { 204 | if (state == Work) return 1; 205 | return 0; 206 | } 207 | 208 | public: 209 | CRemoteXYServer * createServer (uint16_t _port) override { 210 | return new CRemoteXYServer_Ethernet (_port); 211 | } 212 | 213 | 214 | CRemoteXYClient * newClient () override { 215 | return new CRemoteXYClient_Ethernet (); 216 | } 217 | 218 | }; 219 | 220 | 221 | #endif // ethernet_h_ 222 | 223 | #endif //RemoteXYComm_Ethernet_h -------------------------------------------------------------------------------- /src/RemoteXYComm_WiFi.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYComm_WiFi_h 2 | #define RemoteXYComm_WiFi_h 3 | 4 | #include "RemoteXYFunc.h" 5 | #include "RemoteXYDebugLog.h" 6 | #include "RemoteXYComm.h" 7 | 8 | 9 | #if defined (WIFI_AP) && defined (WIFI_STA) && defined (ESP32) && ESP_ARDUINO_VERSION_MAJOR >= 3 10 | #define REMOREXYCOMM_WIFI__ESP32v3 11 | #endif 12 | 13 | // only WiFi.h library 14 | #if defined (WiFi_h) || defined (WiFiNINA_h) || defined (WiFiS3_h) || defined (REMOREXYCOMM_WIFI__ESP32v3) 15 | 16 | #if defined (ESP8266) || defined (ESP32) || defined (WiFiS3_h) 17 | #define REMOREXYCOMM_WIFI__SEND_BUFFER_SIZE 256 18 | #else // arduino shield 19 | #define REMOREXYCOMM_WIFI__SEND_BUFFER_SIZE 64 20 | #endif 21 | 22 | #define REMOREXYCOMM_WIFI__RECONNECT_TIMEOUT 20000 // reconnect in 20 sec 23 | 24 | #if defined (WiFiS3_h) 25 | // The server.available () function can return the same client 26 | // even if it has been connected for a long time. 27 | // Need to cut off clients who are already working 28 | #define REMOREXYCOMM_WIFI__ADDITIONAL_CLIENT_CONTROL 29 | #endif 30 | 31 | class CRemoteXYClient_WiFi : public CRemoteXYClient { 32 | public: 33 | WiFiClient client; 34 | 35 | uint8_t sendBuffer[REMOREXYCOMM_WIFI__SEND_BUFFER_SIZE]; 36 | uint16_t sendBufferCount; 37 | uint16_t sendBytesAvailable; 38 | 39 | public: 40 | uint8_t connect (const char *host, uint16_t port) override { 41 | return client.connect(host, port); 42 | }; 43 | 44 | public: 45 | uint8_t connected () override { 46 | return client.connected(); 47 | }; 48 | 49 | public: 50 | void stop () override { 51 | client.stop (); 52 | }; 53 | 54 | public: 55 | void handler () override { 56 | while (client.available ()) notifyReadByteListener (client.read ()); 57 | } 58 | 59 | 60 | public: 61 | void startWrite (uint16_t len) override { 62 | sendBytesAvailable = len; 63 | sendBufferCount = 0; 64 | } 65 | 66 | public: 67 | void write (uint8_t b) override { 68 | sendBuffer[sendBufferCount++] = b; 69 | sendBytesAvailable--; 70 | if ((sendBufferCount == REMOREXYCOMM_WIFI__SEND_BUFFER_SIZE) || (sendBytesAvailable==0)) { 71 | client.write (sendBuffer, sendBufferCount); 72 | sendBufferCount=0; 73 | } 74 | } 75 | 76 | }; 77 | 78 | class CRemoteXYServer_WiFi : public CRemoteXYServer { 79 | private: 80 | WiFiServer * server; 81 | 82 | #if defined (REMOREXYCOMM_WIFI__ADDITIONAL_CLIENT_CONTROL) 83 | WiFiClient clients[REMOTEXY_MAX_CLIENTS]; 84 | uint8_t clientsConnected[REMOTEXY_MAX_CLIENTS]; 85 | #endif 86 | 87 | public: 88 | CRemoteXYServer_WiFi (uint16_t _port) { 89 | server = new WiFiServer (_port); 90 | } 91 | 92 | 93 | public: 94 | virtual uint8_t begin () override { 95 | 96 | #if defined (REMOREXYCOMM_WIFI__ADDITIONAL_CLIENT_CONTROL) 97 | for (uint8_t i=0; ibegin (); 101 | return 1; 102 | } 103 | 104 | 105 | void stop () override { 106 | #if defined (ESP8266) || defined (ESP32) 107 | server->stop (); 108 | #endif 109 | } 110 | 111 | 112 | 113 | uint8_t available (CRemoteXYClient * client) override { 114 | 115 | #if defined (ESP8266) || defined (ESP32) 116 | if (!server->hasClient()) return 0; 117 | #endif 118 | 119 | #if defined (REMOREXYCOMM_WIFI__ADDITIONAL_CLIENT_CONTROL) 120 | for (uint8_t i=0; iavailable (); 130 | if (cl) { 131 | 132 | if (cl.connected ()) { 133 | 134 | #if defined (ESP8266) 135 | cl.disableKeepAlive (); // remove memory leak 136 | #endif // ESP8266 137 | 138 | #if defined (REMOREXYCOMM_WIFI__ADDITIONAL_CLIENT_CONTROL) 139 | int8_t free = -1; 140 | for (uint8_t i=0; iclient = cl; 154 | return 1; 155 | } 156 | } 157 | return 0; 158 | } 159 | 160 | }; 161 | 162 | 163 | class CRemoteXYComm_WiFi : public CRemoteXYComm { 164 | 165 | private: 166 | char * wifiSsid; 167 | char * wifiPassword; 168 | uint8_t wifiStatus; 169 | uint32_t timeOut; // for reconnect 170 | 171 | 172 | public: 173 | CRemoteXYComm_WiFi (const char * _wifiSsid, const char * _wifiPassword) : CRemoteXYComm () { 174 | wifiSsid = (char *)_wifiSsid; 175 | wifiPassword = (char *)_wifiPassword; 176 | 177 | timeOut = millis (); 178 | wifiStatus = WiFi.status(); 179 | connectToWiFi (); 180 | } 181 | 182 | 183 | void handler () override { 184 | 185 | #if defined(REMOTEXY__DEBUGLOG) 186 | uint8_t prev_wifiStatus = wifiStatus; 187 | #endif 188 | 189 | wifiStatus = WiFi.status(); 190 | 191 | if (wifiStatus == WL_CONNECTED) { 192 | timeOut = millis (); 193 | #if defined(REMOTEXY__DEBUGLOG) 194 | if (prev_wifiStatus != WL_CONNECTED) { 195 | RemoteXYDebugLog.write ("WiFi connected"); 196 | RemoteXYDebugLog.write ("IP: "); 197 | RemoteXYDebugLog.serial->print (WiFi.localIP()); 198 | } 199 | #endif 200 | } 201 | else { // != WL_CONNECTED 202 | 203 | #if defined(REMOTEXY__DEBUGLOG) 204 | if (prev_wifiStatus == WL_CONNECTED) { 205 | RemoteXYDebugLog.write ("WiFi disconnected"); 206 | } 207 | #endif 208 | 209 | if (millis() - timeOut > REMOREXYCOMM_WIFI__RECONNECT_TIMEOUT) { 210 | timeOut = millis (); 211 | connectToWiFi (); 212 | } 213 | } 214 | } 215 | 216 | private: 217 | void connectToWiFi () { 218 | 219 | #if defined (ESP8266) || defined (ESP32) 220 | 221 | WiFi.disconnect(); 222 | WiFi.softAPdisconnect(true); 223 | WiFi.mode(WIFI_STA); 224 | WiFi.setAutoReconnect(false); 225 | 226 | #else // NOT ESP 227 | 228 | if (wifiStatus == WL_NO_SHIELD) { 229 | #if defined(REMOTEXY__DEBUGLOG) 230 | RemoteXYDebugLog.write("WiFi module was not found"); 231 | #endif 232 | return; 233 | } 234 | 235 | #endif // ESP 236 | 237 | 238 | #if defined(REMOTEXY__DEBUGLOG) 239 | RemoteXYDebugLog.write("Сonnecting to WiFi: "); 240 | RemoteXYDebugLog.writeAdd(wifiSsid); 241 | RemoteXYDebugLog.writeAdd(" ..."); 242 | #endif 243 | 244 | WiFi.begin(wifiSsid, wifiPassword); 245 | 246 | } 247 | 248 | 249 | public: 250 | uint8_t configured () override { 251 | if (wifiStatus == WL_CONNECTED) return 1; 252 | return 0; 253 | } 254 | 255 | public: 256 | CRemoteXYServer * createServer (uint16_t _port) override { 257 | return new CRemoteXYServer_WiFi (_port); 258 | } 259 | 260 | 261 | CRemoteXYClient * newClient () override { 262 | return new CRemoteXYClient_WiFi (); 263 | } 264 | 265 | }; 266 | 267 | 268 | 269 | class CRemoteXYComm_WiFiPoint : public CRemoteXYComm { 270 | 271 | uint8_t state; 272 | 273 | public: 274 | CRemoteXYComm_WiFiPoint (const char * _wifiSsid, const char * _wifiPassword) : CRemoteXYComm () { 275 | 276 | 277 | #if defined(REMOTEXY__DEBUGLOG) 278 | RemoteXYDebugLog.write("Creating WiFi point: "); 279 | RemoteXYDebugLog.writeAdd(_wifiSsid); 280 | RemoteXYDebugLog.writeAdd(" ..."); 281 | #endif 282 | 283 | #if defined (ESP8266) || defined (ESP32) 284 | // ESP8266 and ESP32 285 | 286 | WiFi.mode(WIFI_AP); 287 | WiFi.softAP(_wifiSsid, _wifiPassword); 288 | state = 1; 289 | #if defined(REMOTEXY__DEBUGLOG) 290 | RemoteXYDebugLog.write("WiFi point created"); 291 | RemoteXYDebugLog.write ("IP: "); 292 | RemoteXYDebugLog.serial->print (WiFi.softAPIP()); 293 | #endif 294 | 295 | 296 | #elif defined (WiFiNINA_h) || defined (WiFiS3_h) || defined (ARDUINO_ARCH_MBED) 297 | // WiFiNINA.h 298 | // WiFiS3.h 299 | // MBED platform 300 | 301 | state = 0; 302 | if (WiFi.status() == WL_NO_SHIELD) { 303 | #if defined(REMOTEXY__DEBUGLOG) 304 | RemoteXYDebugLog.write("WiFi module was not found"); 305 | #endif 306 | return; 307 | } 308 | if (WiFi.beginAP (_wifiSsid, _wifiPassword) != WL_AP_LISTENING) { 309 | #if defined(REMOTEXY__DEBUGLOG) 310 | RemoteXYDebugLog.write("WiFi point was not created"); 311 | #endif 312 | return; 313 | } 314 | state = 1; 315 | 316 | #if defined(REMOTEXY__DEBUGLOG) 317 | RemoteXYDebugLog.write("WiFi point created"); 318 | RemoteXYDebugLog.write ("IP: "); 319 | RemoteXYDebugLog.serial->print (WiFi.localIP()); 320 | #endif 321 | 322 | #else 323 | // other boards not support AP mode 324 | 325 | state = 0; 326 | #if defined(REMOTEXY__DEBUGLOG) 327 | RemoteXYDebugLog.write("WiFi module does not support AP mode"); 328 | #endif 329 | 330 | #endif // ESP 331 | 332 | } 333 | 334 | public: 335 | uint8_t configured () override { 336 | return state; 337 | } 338 | 339 | 340 | public: 341 | CRemoteXYServer * createServer (uint16_t _port) override { 342 | return new CRemoteXYServer_WiFi (_port); 343 | } 344 | 345 | 346 | CRemoteXYClient * newClient () override { 347 | return new CRemoteXYClient_WiFi (); 348 | } 349 | 350 | }; 351 | 352 | 353 | #endif // WiFi_h 354 | 355 | #endif //RemoteXYComm_WiFi_h -------------------------------------------------------------------------------- /src/RemoteXYConnection.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYConnection_h 2 | #define RemoteXYConnection_h 3 | 4 | #include "RemoteXYComm.h" 5 | #include "RemoteXYWire.h" 6 | #include "RemoteXYCloudServer.h" 7 | 8 | #define UNUSED(x) (void)(x) 9 | 10 | class CRemoteXYConnection { 11 | 12 | public: 13 | virtual void init (CRemoteXYData * _data) {UNUSED (_data);}; 14 | 15 | public: 16 | virtual void handler () {}; 17 | virtual void handleWire (CRemoteXYWire * wire) {UNUSED (wire);}; 18 | virtual void stopThreadListener (CRemoteXYWire * wire) {UNUSED (wire);}; 19 | 20 | }; 21 | 22 | 23 | class CRemoteXYConnectionComm : public CRemoteXYConnection { 24 | public: 25 | CRemoteXYConnectionComm * next; 26 | CRemoteXYComm * comm; 27 | 28 | public: 29 | CRemoteXYConnectionComm (CRemoteXYComm * _comm) { 30 | comm = _comm; 31 | } 32 | 33 | }; 34 | 35 | #endif //RemoteXYConnection_h -------------------------------------------------------------------------------- /src/RemoteXYConnectionCloud.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYConnectionCloud_h 2 | #define RemoteXYConnectionCloud_h 3 | 4 | #include "RemoteXYDebugLog.h" 5 | #include "RemoteXYConnection.h" 6 | #include "RemoteXYThread.h" 7 | 8 | #define REMOTEXY_CLOUDCLIENT_RETRY_TIMEOUT 20000 9 | 10 | class CRemoteXYConnectionCloud: public CRemoteXYConnectionComm, CRemoteXYCloudClientAvailableListener { 11 | public: 12 | uint16_t port; 13 | CRemoteXYCloudServer * cloudServer; 14 | const char * cloudHost; 15 | const char * cloudToken; 16 | CRemoteXYData * data; 17 | CRemoteXYClient * client; 18 | uint32_t timeOut; 19 | 20 | public: 21 | CRemoteXYConnectionCloud (CRemoteXYComm * _comm, const char * _cloudHost, uint16_t _port, const char * _cloudToken) : CRemoteXYConnectionComm (_comm) { 22 | port = _port; 23 | cloudHost = _cloudHost; 24 | cloudToken = _cloudToken; 25 | } 26 | 27 | public: 28 | void init (CRemoteXYData * _data) override { 29 | data = _data; 30 | cloudServer = new CRemoteXYCloudServer (data, cloudToken, this); 31 | client = comm->newClient (); 32 | timeOut = -REMOTEXY_CLOUDCLIENT_RETRY_TIMEOUT; 33 | } 34 | 35 | void handler () override { 36 | 37 | if (comm->configured ()) { 38 | if (cloudServer->running ()) { 39 | cloudServer->handler(); 40 | timeOut = millis(); 41 | } 42 | else { // not serverRunning 43 | if (millis() - timeOut > REMOTEXY_CLOUDCLIENT_RETRY_TIMEOUT) { 44 | #if defined(REMOTEXY__DEBUGLOG) 45 | RemoteXYDebugLog.write ("Connecting to cloud: "); 46 | RemoteXYDebugLog.writeAdd (cloudHost); 47 | RemoteXYDebugLog.writeAdd (" "); 48 | RemoteXYDebugLog.writeAdd (port); 49 | RemoteXYDebugLog.writeAdd (" .."); 50 | #endif 51 | if (client->connect (cloudHost, port)) { 52 | #if defined(REMOTEXY__DEBUGLOG) 53 | RemoteXYDebugLog.write ("Cloud server connected"); 54 | #endif 55 | cloudServer->begin (client); 56 | } 57 | #if defined(REMOTEXY__DEBUGLOG) 58 | else { 59 | RemoteXYDebugLog.write ("Cloud server not available"); 60 | } 61 | #endif 62 | timeOut = millis(); 63 | } 64 | } 65 | } 66 | else cloudServer->stop (); 67 | if (!cloudServer->running ()) { 68 | if (client->connected ()) { 69 | client->stop (); 70 | } 71 | } 72 | } 73 | 74 | void clientAvailable (CRemoteXYWireCloud * cloudWire) override { 75 | if (CRemoteXYThread::runningCount (data) < REMOTEXY_MAX_CLIENTS) { 76 | CRemoteXYThread::startThread (data, this, cloudWire, 1); 77 | } 78 | else { 79 | cloudWire->stop (); 80 | #if defined(REMOTEXY__DEBUGLOG) 81 | RemoteXYDebugLog.write ("Client reject"); 82 | #endif 83 | } 84 | 85 | } 86 | 87 | 88 | void handleWire (CRemoteXYWire * wire) override { 89 | if (cloudServer->running () && comm->configured ()) wire->handler (); 90 | else stopThreadListener (wire); 91 | } 92 | 93 | void stopThreadListener (CRemoteXYWire * wire) override { 94 | wire->stop (); 95 | } 96 | 97 | 98 | 99 | }; 100 | 101 | 102 | #endif // RemoteXYConnectionCloud_h -------------------------------------------------------------------------------- /src/RemoteXYConnectionServer.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYConnectionServer_h 2 | #define RemoteXYConnectionServer_h 3 | 4 | #include "RemoteXYDebugLog.h" 5 | #include "RemoteXYConnection.h" 6 | #include "RemoteXYWireStream.h" 7 | #include "RemoteXYThread.h" 8 | 9 | 10 | 11 | class CRemoteXYConnectionServer: public CRemoteXYConnectionComm, public CRemoteXYClientAvailableListener { 12 | public: 13 | uint16_t port; 14 | CRemoteXYData * data; 15 | CRemoteXYServer * server; 16 | CRemoteXYClient * clients; 17 | CRemoteXYWireStream * wires; 18 | uint8_t serverRunning; 19 | 20 | 21 | CRemoteXYConnectionServer (CRemoteXYComm * _comm, uint16_t _port = 0) : CRemoteXYConnectionComm (_comm) { 22 | port = _port; 23 | clients = NULL; 24 | server = comm->createServer (port); 25 | server->setClientAvailabListener (this); 26 | #if defined(REMOTEXY__DEBUGLOG) 27 | if (!server) { 28 | RemoteXYDebugLog.write ("Server was not created"); 29 | } 30 | #endif 31 | serverRunning = 0; 32 | wires = NULL; 33 | } 34 | 35 | void init (CRemoteXYData * _data) { 36 | data = _data; 37 | } 38 | 39 | public: 40 | void handler () override { 41 | if (!server) return; 42 | if (comm->configured ()) { 43 | if (serverRunning) clientAvailable (); 44 | else { 45 | if (server->begin ()) { 46 | serverRunning=1; 47 | #if defined(REMOTEXY__DEBUGLOG) 48 | RemoteXYDebugLog.write ("Server opened on port "); 49 | RemoteXYDebugLog.writeAdd (port); 50 | #endif 51 | } 52 | #if defined(REMOTEXY__DEBUGLOG) 53 | else { 54 | RemoteXYDebugLog.write ("Server was not started"); 55 | } 56 | #endif 57 | } 58 | } 59 | else { 60 | if (serverRunning) { 61 | server->stop (); 62 | serverRunning =0; 63 | } 64 | } 65 | } 66 | 67 | void clientAvailable () override { 68 | CRemoteXYClient * client = clients; 69 | while (client) { 70 | if (!client->connected ()) break; 71 | client = client->next; 72 | } 73 | if (!client) { 74 | client = comm->newClient (); 75 | client->next = clients; 76 | clients = client; 77 | } 78 | if (server->available (client)) { 79 | 80 | if (CRemoteXYThread::runningCount (data) < REMOTEXY_MAX_CLIENTS) { 81 | CRemoteXYWireStream * wire = wires; 82 | while (wire) { 83 | if (!wire->running()) break; 84 | wire = wire->next; 85 | } 86 | if (!wire) { 87 | wire = new CRemoteXYWireStream (data); 88 | wire->next = wires; 89 | wires = wire; 90 | } 91 | wire->begin (client); 92 | CRemoteXYThread::startThread (data, this, wire, 1); 93 | } 94 | else { 95 | client->stop (); 96 | #if defined(REMOTEXY__DEBUGLOG) 97 | RemoteXYDebugLog.write ("Client reject"); 98 | #endif 99 | } 100 | } 101 | 102 | } 103 | 104 | void handleWire (CRemoteXYWire * wire) override { 105 | CRemoteXYClient * client = ((CRemoteXYWireStream*)wire)->getClient (); 106 | if (client) { 107 | if (client->connected () && serverRunning && comm->configured ()) wire->handler (); 108 | else stopThreadListener (wire); 109 | } 110 | } 111 | 112 | void stopThreadListener (CRemoteXYWire * wire) override { 113 | CRemoteXYClient * client = ((CRemoteXYWireStream*)wire)->getClient (); 114 | if (client) { 115 | client->stop (); 116 | wire->stop (); 117 | } 118 | } 119 | 120 | 121 | 122 | }; 123 | 124 | 125 | #endif // RemoteXYConnectionServer_h -------------------------------------------------------------------------------- /src/RemoteXYConnectionStream.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYConnectionStream_h 2 | #define RemoteXYConnectionStream_h 3 | 4 | #include "RemoteXYDebugLog.h" 5 | #include "RemoteXYConnection.h" 6 | #include "RemoteXYThread.h" 7 | 8 | class CRemoteXYConnectionStream: public CRemoteXYConnection { 9 | CRemoteXYStream * stream; 10 | 11 | public: 12 | CRemoteXYConnectionStream (CRemoteXYStream * _stream) { 13 | stream = _stream; 14 | } 15 | 16 | void init (CRemoteXYData * _data) override { 17 | CRemoteXYWireStream * wire = new CRemoteXYWireStream (_data); 18 | wire->begin (stream); 19 | CRemoteXYThread::startThread (_data, this, wire, 0); 20 | }; 21 | 22 | void handleWire (CRemoteXYWire * wire) override { 23 | wire->handler (); 24 | }; 25 | 26 | }; 27 | 28 | #endif // CRemoteXYConnectionStream -------------------------------------------------------------------------------- /src/RemoteXYDebugLog.h: -------------------------------------------------------------------------------- 1 | #ifndef _REMOTEXY_DEBUGLOG_H_ 2 | #define _REMOTEXY_DEBUGLOG_H_ 3 | 4 | #if defined(REMOTEXY__DEBUGLOG) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #ifndef REMOTEXY__DEBUGLOG_SERIAL 11 | #define REMOTEXY__DEBUGLOG_SERIAL Serial 12 | #endif 13 | #ifndef REMOTEXY__DEBUGLOG_SPEED 14 | #define REMOTEXY__DEBUGLOG_SPEED 115200 15 | #endif 16 | 17 | 18 | class CRemoteXYDebugLog { 19 | public: 20 | HardwareSerial * serial; 21 | long speed; 22 | uint8_t inited; 23 | 24 | private: 25 | uint8_t debug_flags; 26 | uint8_t debug_hexcounter; 27 | 28 | public: 29 | CRemoteXYDebugLog (HardwareSerial * _serial, long _speed) { 30 | debug_flags=0; 31 | serial = _serial; 32 | speed = _speed; 33 | inited = 0; 34 | } 35 | 36 | public: 37 | void init () { 38 | if (!inited) { 39 | serial->begin (speed); 40 | serial->println (); 41 | write ("Debug log started"); 42 | inited = 1; 43 | } 44 | } 45 | 46 | 47 | public: 48 | void writeTime () { 49 | uint32_t d = millis(); 50 | long ds = d/1000; 51 | long dm = d%1000; 52 | char s[15]; 53 | sprintf (s, "[%5ld.%03ld] ",ds, dm); 54 | serial->println (); 55 | serial->print (s); 56 | } 57 | 58 | 59 | public: 60 | void write (const char *s) { 61 | debug_flags = 0; 62 | writeTime (); 63 | serial->print(s); 64 | } 65 | 66 | public: 67 | void writeAdd (const char *s) { 68 | serial->print(s); 69 | } 70 | 71 | 72 | public: 73 | void writeAdd (uint16_t i) { 74 | serial->print(i); 75 | } 76 | 77 | public: 78 | void writeAdd (uint32_t i) { 79 | serial->print(i); 80 | } 81 | 82 | public: 83 | void writeAdd (int i) { 84 | serial->print(i); 85 | } 86 | 87 | public: 88 | void writeAdd (long i) { 89 | serial->print(i); 90 | } 91 | 92 | public: 93 | void writeInput (const char *s) { 94 | if ((debug_flags & 0x01)==0) { 95 | writeTime (); 96 | serial->print("<- "); 97 | } 98 | debug_flags = 0x01; 99 | serial->print(s); 100 | } 101 | 102 | public: 103 | void writeOutput (const char *s) { 104 | if ((debug_flags & 0x02)==0) { 105 | writeTime (); 106 | serial->print("-> "); 107 | } 108 | debug_flags = 0x02; 109 | serial->print(s); 110 | } 111 | 112 | public: 113 | void writeInputHex (uint8_t b) { 114 | if ((debug_flags & 0x01)==0) { 115 | writeTime (); 116 | serial->print("<-"); 117 | debug_hexcounter=0; 118 | } 119 | debug_flags = 0x01; 120 | writeHex (b); 121 | } 122 | 123 | public: 124 | void writeOutputHex (uint8_t b) { 125 | if ((debug_flags & 0x02)==0) { 126 | writeTime (); 127 | serial->print("->"); 128 | debug_hexcounter=0; 129 | } 130 | debug_flags = 0x02; 131 | writeHex (b); 132 | } 133 | 134 | public: 135 | void writeInputChar (char s) { 136 | if ((debug_flags & 0x01)==0) { 137 | writeTime (); 138 | serial->print("<- "); 139 | } 140 | debug_flags = 0x01; 141 | serial->print(s); 142 | } 143 | 144 | public: 145 | void writeInputNewString () { 146 | debug_flags = 0; 147 | } 148 | 149 | public: 150 | void writeHex (uint8_t b) { 151 | debug_hexcounter++; 152 | if (debug_hexcounter>16) { 153 | serial->println(); 154 | serial->print(" "); 155 | debug_hexcounter=1; 156 | } 157 | serial->print(' '); 158 | serial->print(b>>4, HEX); 159 | serial->print(b&0x0f, HEX); 160 | } 161 | 162 | public: 163 | void writeAvailableMemory () { 164 | write ( "Available memory: " ); 165 | writeAdd (availableMemory()); 166 | } 167 | 168 | 169 | 170 | private: 171 | uint32_t availableMemory() { 172 | #if defined (ESP8266) || defined (ESP32) 173 | return ESP.getFreeHeap (); 174 | #elif defined (__AVR__) 175 | uint16_t size = RAMEND; 176 | uint8_t *buf; 177 | while ((buf = (uint8_t *)malloc(size)) == NULL) size--; 178 | free(buf); 179 | return size; 180 | #else 181 | return 0; 182 | #endif 183 | } 184 | 185 | 186 | }; 187 | 188 | 189 | CRemoteXYDebugLog RemoteXYDebugLog (& REMOTEXY__DEBUGLOG_SERIAL, REMOTEXY__DEBUGLOG_SPEED); 190 | 191 | 192 | #endif //REMOTEXY__DEBUGLOG 193 | 194 | #endif //_REMOTEXY_DEBUGLOG_H_ -------------------------------------------------------------------------------- /src/RemoteXYFunc.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYFunc_h 2 | #define RemoteXYFunc_h 3 | 4 | #include 5 | 6 | 7 | char* rxy_itos (uint16_t i, char* s) { 8 | uint8_t len=0; 9 | char *p=s+5; 10 | while (i) { 11 | *p--=i%10+'0'; 12 | i/=10; 13 | len++; 14 | } 15 | for (i=0; i0; i--) { 31 | b=rxy_xctoi (*s++)<<4; 32 | b|=rxy_xctoi (*s++); 33 | *m++=b; 34 | s++; 35 | } 36 | } 37 | 38 | // s = "000.000.000.000.000" 39 | uint32_t rxy_getIntVers (const char* s) { 40 | uint32_t ver = 0; 41 | uint32_t m = 1; 42 | uint8_t d = 0; 43 | const char * p = s; 44 | while (*p!=0) p++; 45 | while (p != s) { 46 | p--; 47 | if (*p == 0x2E) { 48 | while (d<3) { 49 | m *=10; 50 | d++; 51 | } 52 | d=0; 53 | } 54 | else { 55 | ver += (*p - 0x30) * m; 56 | m *=10; 57 | d++; 58 | } 59 | } 60 | return ver; 61 | } 62 | 63 | #endif //RemoteXYFunc_h -------------------------------------------------------------------------------- /src/RemoteXYStream.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYStream_h 2 | #define RemoteXYStream_h 3 | 4 | #include 5 | #include "RemoteXYDebugLog.h" 6 | 7 | #define UNUSED(x) (void)(x) 8 | 9 | class CRemoteXYReadByteListener { 10 | public: 11 | virtual void readByte (uint8_t byte) = 0; 12 | }; 13 | 14 | 15 | class CRemoteXYStream { 16 | private: 17 | CRemoteXYReadByteListener * readByteListener; 18 | 19 | 20 | public: 21 | CRemoteXYStream () { 22 | readByteListener = NULL; 23 | #if defined(REMOTEXY__DEBUGLOG) 24 | RemoteXYDebugLog.init (); 25 | #endif 26 | } 27 | 28 | public: 29 | void setReadByteListener (CRemoteXYReadByteListener * listener) { 30 | readByteListener = listener; 31 | } 32 | 33 | public: 34 | void notifyReadByteListener (uint8_t byte) { 35 | if (readByteListener) readByteListener->readByte (byte); 36 | } 37 | 38 | public: 39 | virtual void handler () {}; 40 | virtual void startWrite (uint16_t size) {UNUSED (size);}; 41 | virtual void write (uint8_t byte) {UNUSED (byte);}; 42 | }; 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | #endif //RemoteXYStream_h -------------------------------------------------------------------------------- /src/RemoteXYStream_AltSoftSerial.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYStream_AltSoftSerial_h 2 | #define RemoteXYStream_AltSoftSerial_h 3 | 4 | #if defined(AltSoftSerial_h) 5 | // AltSoftSerial always uses these pins: 6 | // 7 | // Board Transmit Receive PWM Unusable 8 | // ----- -------- ------- ------------ 9 | // Teensy 3.0 & 3.1 21 20 22 10 | // Teensy 2.0 9 10 (none) 11 | // Teensy++ 2.0 25 4 26, 27 12 | // Arduino Uno 9 8 10 13 | // Arduino Leonardo 5 13 (none) 14 | // Arduino Mega 46 48 44, 45 15 | // Wiring-S 5 6 4 16 | // Sanguino 13 14 12 17 | 18 | #include "RemoteXYStream_Stream.h" 19 | 20 | 21 | class CRemoteXYStream_AltSoftSerial : public CRemoteXYStream_Stream { 22 | 23 | public: 24 | CRemoteXYStream_AltSoftSerial (long _serialSpeed) : CRemoteXYStream_Stream () { 25 | AltSoftSerial * serial = new AltSoftSerial (); 26 | serial->begin (_serialSpeed); 27 | setStream (serial); 28 | #if defined(REMOTEXY__DEBUGLOG) 29 | RemoteXYDebugLog.write("Init alt soft serial "); 30 | RemoteXYDebugLog.writeAdd(_serialSpeed); 31 | RemoteXYDebugLog.writeAdd(" baud"); 32 | #endif 33 | } 34 | 35 | }; 36 | 37 | 38 | #endif // AltSoftSerial_h 39 | 40 | #endif //RemoteXYStream_AltSoftSerial_h -------------------------------------------------------------------------------- /src/RemoteXYStream_ArduinoBLE.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYStream_ArduinoBLE_h 2 | #define RemoteXYStream_ArduinoBLE_h 3 | 4 | #if defined(_ARDUINO_BLE_H_) 5 | 6 | #include "RemoteXYStream.h" 7 | 8 | #define REMOTEXYCOMM_ARDUINOBLE__SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E" // NORDIC UART service UUID 9 | #define REMOTEXYCOMM_ARDUINOBLE__RX_CHARACTERISTIC_UUID "6E400002-B5A3-F393-E0A9-E50E24DCCA9E" 10 | #define REMOTEXYCOMM_ARDUINOBLE__TX_CHARACTERISTIC_UUID "6E400003-B5A3-F393-E0A9-E50E24DCCA9E" 11 | #define REMOTEXYCOMM_ARDUINOBLE__CHARACTERISTIC_SIZE 20 12 | #define REMOTEXYCOMM_ARDUINOBLE__RECEIVE_BUFFER_SIZE 1024 13 | 14 | class CRemoteXYStream_ArduinoBLE; 15 | CRemoteXYStream_ArduinoBLE * CRemoteXYStream_ArduinoBLE_instance = NULL; 16 | void CRemoteXYStream_ArduinoBLE_onBLEWritten (BLEDevice central, BLECharacteristic characteristic); 17 | 18 | 19 | class CRemoteXYStream_ArduinoBLE : public CRemoteXYStream { 20 | 21 | private: 22 | 23 | uint8_t failed; 24 | uint8_t connected; 25 | 26 | BLEService * service; 27 | BLECharacteristic * rxCharacteristic; 28 | BLECharacteristic * txCharacteristic; 29 | BLEDescriptor * txDescriptor; 30 | 31 | uint8_t sendBuffer[REMOTEXYCOMM_ARDUINOBLE__CHARACTERISTIC_SIZE]; 32 | uint16_t sendBufferCount; 33 | uint16_t sendBytesAvailable; 34 | 35 | uint8_t receiveBuffer[REMOTEXYCOMM_ARDUINOBLE__RECEIVE_BUFFER_SIZE]; 36 | uint16_t receiveBufferStart; 37 | uint16_t receiveBufferPos; 38 | uint16_t receiveBufferCount; 39 | 40 | 41 | public: 42 | CRemoteXYStream_ArduinoBLE (const char * _bleDeviceName) : CRemoteXYStream () { 43 | CRemoteXYStream_ArduinoBLE_instance = this; 44 | 45 | #if defined(REMOTEXY__DEBUGLOG) 46 | RemoteXYDebugLog.write("Init Arduino BLE"); 47 | #endif 48 | connected = 0; 49 | 50 | if (!BLE.begin()) { 51 | failed = 1; 52 | #if defined(REMOTEXY__DEBUGLOG) 53 | RemoteXYDebugLog.write("Starting BLE module failed"); 54 | #endif 55 | return; 56 | } 57 | 58 | receiveBufferCount = 0; 59 | receiveBufferStart = 0; 60 | receiveBufferPos = 0; 61 | 62 | 63 | BLE.setLocalName(_bleDeviceName); 64 | BLE.setDeviceName(_bleDeviceName); 65 | service = new BLEService(REMOTEXYCOMM_ARDUINOBLE__SERVICE_UUID); 66 | BLE.setAdvertisedService(*service); 67 | rxCharacteristic = new BLECharacteristic(REMOTEXYCOMM_ARDUINOBLE__RX_CHARACTERISTIC_UUID, BLEWriteWithoutResponse, REMOTEXYCOMM_ARDUINOBLE__CHARACTERISTIC_SIZE); 68 | txCharacteristic = new BLECharacteristic(REMOTEXYCOMM_ARDUINOBLE__TX_CHARACTERISTIC_UUID, BLENotify, REMOTEXYCOMM_ARDUINOBLE__CHARACTERISTIC_SIZE); 69 | uint8_t descriptorValue[2] = {00, 00}; 70 | txDescriptor = new BLEDescriptor ("2902", descriptorValue, sizeof (descriptorValue)); 71 | txCharacteristic->addDescriptor (*txDescriptor); 72 | 73 | service->addCharacteristic(*rxCharacteristic); 74 | service->addCharacteristic(*txCharacteristic); 75 | 76 | rxCharacteristic->setEventHandler(BLEWritten, CRemoteXYStream_ArduinoBLE_onBLEWritten); 77 | 78 | BLE.addService(*service); 79 | 80 | rxCharacteristic->writeValue((uint8_t)0); 81 | txCharacteristic->writeValue((uint8_t)0); 82 | BLE.advertise(); 83 | 84 | 85 | #if defined(REMOTEXY__DEBUGLOG) 86 | RemoteXYDebugLog.write("Arduino BLE started"); 87 | #endif 88 | failed = 0; 89 | 90 | } 91 | 92 | 93 | void startWrite (uint16_t len) override { 94 | if (failed !=0) return; 95 | sendBytesAvailable = len; 96 | sendBufferCount = 0; 97 | } 98 | 99 | void write (uint8_t b) override { 100 | if (failed !=0) return; 101 | sendBuffer[sendBufferCount++] = b; 102 | sendBytesAvailable--; 103 | if ((sendBufferCount == REMOTEXYCOMM_ARDUINOBLE__CHARACTERISTIC_SIZE) || (sendBytesAvailable == 0)) { 104 | if (connected != 0) { 105 | txCharacteristic->writeValue(sendBuffer, sendBufferCount); 106 | BLE.poll(); 107 | } 108 | sendBufferCount = 0; 109 | } 110 | } 111 | 112 | void handler () override { 113 | if (failed !=0) return; 114 | if (BLE.connected()) { 115 | if (connected == 0) { 116 | receiveBufferCount = 0; 117 | receiveBufferStart = 0; 118 | receiveBufferPos = 0; 119 | connected = 1; 120 | #if defined(REMOTEXY__DEBUGLOG) 121 | RemoteXYDebugLog.write("BLE client connected"); 122 | #endif 123 | } 124 | } 125 | else { 126 | if (connected != 0) { 127 | connected = 0; 128 | #if defined(REMOTEXY__DEBUGLOG) 129 | RemoteXYDebugLog.write("BLE client disconnected"); 130 | #endif 131 | } 132 | } 133 | 134 | uint8_t b; 135 | BLE.poll(); 136 | while (receiveBufferCount > 0) { 137 | b = receiveBuffer[receiveBufferStart++]; 138 | if (receiveBufferStart >= REMOTEXYCOMM_ARDUINOBLE__RECEIVE_BUFFER_SIZE) receiveBufferStart=0; 139 | receiveBufferCount--; 140 | notifyReadByteListener (b); 141 | } 142 | 143 | /* 144 | BLE.poll(); 145 | if (rxCharacteristic->written ()) { 146 | uint8_t buff[REMOTEXYCOMM_ARDUINOBLE__CHARACTERISTIC_SIZE]; 147 | uint8_t cnt = rxCharacteristic->readValue (buff, REMOTEXYCOMM_ARDUINOBLE__CHARACTERISTIC_SIZE); 148 | for (uint8_t i=0; ireadValue (buff, REMOTEXYCOMM_ARDUINOBLE__CHARACTERISTIC_SIZE); 159 | 160 | for (uint8_t i = 0; i < cnt; i++) { 161 | receiveBuffer[receiveBufferPos++] = buff[i]; 162 | if (receiveBufferPos >= REMOTEXYCOMM_ARDUINOBLE__RECEIVE_BUFFER_SIZE) receiveBufferPos=0; 163 | if (receiveBufferCount < REMOTEXYCOMM_ARDUINOBLE__RECEIVE_BUFFER_SIZE) receiveBufferCount++; 164 | else { 165 | receiveBufferStart++; 166 | if (receiveBufferStart >= REMOTEXYCOMM_ARDUINOBLE__RECEIVE_BUFFER_SIZE) receiveBufferStart=0; 167 | } 168 | } 169 | } 170 | }; 171 | 172 | 173 | void CRemoteXYStream_ArduinoBLE_onBLEWritten (BLEDevice central, BLECharacteristic characteristic) { 174 | if (CRemoteXYStream_ArduinoBLE_instance != NULL) { 175 | CRemoteXYStream_ArduinoBLE_instance->onBLEWritten (); 176 | } 177 | } 178 | 179 | 180 | 181 | #endif // _ARDUINO_BLE_H_ 182 | 183 | #endif //RemoteXYStream_ArduinoBLE_h -------------------------------------------------------------------------------- /src/RemoteXYStream_BLEDevice.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYStream_BLEDevice_h 2 | #define RemoteXYStream_BLEDevice_h 3 | 4 | #if defined(MAIN_BLEDevice_H_) 5 | 6 | #include "RemoteXYComm.h" 7 | #include 8 | 9 | 10 | #define REMOTEXYCOMM_BLEDEVICE__SEND_BUFFER_SIZE 20 11 | #define REMOTEXYCOMM_BLEDEVICE__RECEIVE_BUFFER_SIZE 1024 12 | #define REMOTEXYCOMM_BLEDEVICE__SERVICE_UUID "0000FFE0-0000-1000-8000-00805F9B34FB" // UART service UUID 13 | #define REMOTEXYCOMM_BLEDEVICE__CHARACTERISTIC_UUID_RXTX "0000FFE1-0000-1000-8000-00805F9B34FB" 14 | 15 | #define REMOTEXYCOMM_BLEDEVICE__SEND_TIME_FOR_ONE_PACKAGE 7 // test min 5 ms 16 | #define REMOTEXYCOMM_BLEDEVICE__SEND_BYTES_BEFORE_OVERFLOW 500 // test max 600 bytes 17 | 18 | 19 | class CRemoteXYStream_BLEDevice : public CRemoteXYStream, BLEServerCallbacks, BLECharacteristicCallbacks { 20 | 21 | protected: 22 | const char * bleDeviceName; // need to delete 23 | 24 | BLEServer *pServer; 25 | BLECharacteristic * pRxTxCharacteristic; 26 | 27 | uint8_t sendBuffer[REMOTEXYCOMM_BLEDEVICE__SEND_BUFFER_SIZE]; 28 | uint16_t sendBufferCount; 29 | uint16_t sendBytesAvailable; 30 | 31 | uint16_t sendCount; 32 | uint8_t sendBLEBufferOverflow; 33 | 34 | uint8_t receiveBuffer[REMOTEXYCOMM_BLEDEVICE__RECEIVE_BUFFER_SIZE]; 35 | uint16_t receiveBufferStart; 36 | uint16_t receiveBufferPos; 37 | uint16_t receiveBufferCount; 38 | 39 | volatile uint8_t receiveBufferLook; 40 | 41 | 42 | public: 43 | CRemoteXYStream_BLEDevice (const char * _bleDeviceName) : CRemoteXYStream () { 44 | bleDeviceName = _bleDeviceName; 45 | 46 | receiveBufferLook = 0; 47 | receiveBufferCount = 0; 48 | receiveBufferStart = 0; 49 | receiveBufferPos = 0; 50 | receiveBufferCount = 0; 51 | 52 | #if defined(REMOTEXY__DEBUGLOG) 53 | RemoteXYDebugLog.write("Init ESP32 BLE on chip"); 54 | #endif 55 | // Create the BLE Device 56 | BLEDevice::init(_bleDeviceName); 57 | 58 | // Create the BLE Server 59 | pServer = BLEDevice::createServer(); 60 | pServer->setCallbacks(this); 61 | 62 | // Create the BLE Service 63 | BLEService *pService = pServer->createService(REMOTEXYCOMM_BLEDEVICE__SERVICE_UUID); 64 | 65 | // Create a BLE Characteristic 66 | pRxTxCharacteristic = pService->createCharacteristic( 67 | REMOTEXYCOMM_BLEDEVICE__CHARACTERISTIC_UUID_RXTX, 68 | BLECharacteristic::PROPERTY_READ | 69 | BLECharacteristic::PROPERTY_NOTIFY | 70 | BLECharacteristic::PROPERTY_WRITE_NR 71 | ); 72 | 73 | BLE2902 *ble2902 = new BLE2902(); 74 | ble2902->setNotifications(true); 75 | pRxTxCharacteristic->addDescriptor(ble2902); 76 | pRxTxCharacteristic->setCallbacks(this); 77 | 78 | // Start the service 79 | pService->start(); 80 | 81 | // Start advertising 82 | pServer->getAdvertising()->addServiceUUID(pService->getUUID()); 83 | pServer->getAdvertising()->start(); 84 | 85 | #if defined(REMOTEXY__DEBUGLOG) 86 | RemoteXYDebugLog.write("BLE started"); 87 | #endif 88 | 89 | } 90 | 91 | void onConnect(BLEServer* pServer) { 92 | #if defined(REMOTEXY__DEBUGLOG) 93 | RemoteXYDebugLog.write("BLE client connected"); 94 | #endif 95 | receiveBufferStart = 0; 96 | receiveBufferPos = 0; 97 | receiveBufferCount = 0; 98 | }; 99 | 100 | void onDisconnect(BLEServer* pServer) { 101 | #if defined(REMOTEXY__DEBUGLOG) 102 | RemoteXYDebugLog.write("BLE client disconnected"); 103 | #endif 104 | receiveBufferCount = 0; 105 | pServer->getAdvertising ()->start (); 106 | } 107 | 108 | void onWrite (BLECharacteristic *pCharacteristic) { 109 | 110 | #if (ESP_ARDUINO_VERSION_MAJOR >= 3) 111 | String rxValue = pCharacteristic->getValue(); 112 | #else 113 | std::string rxValue = pCharacteristic->getValue(); 114 | #endif 115 | if (rxValue.length() > 0) { 116 | while (receiveBufferLook!=0) { delay(1); } 117 | receiveBufferLook=1; 118 | for (uint16_t i = 0; i < rxValue.length(); i++) { 119 | uint8_t b = (uint8_t)rxValue[i]; 120 | receiveBuffer[receiveBufferPos++] = b; 121 | if (receiveBufferPos >= REMOTEXYCOMM_BLEDEVICE__RECEIVE_BUFFER_SIZE) receiveBufferPos=0; 122 | if (receiveBufferCount < REMOTEXYCOMM_BLEDEVICE__RECEIVE_BUFFER_SIZE) receiveBufferCount++; 123 | else { 124 | receiveBufferStart++; 125 | if (receiveBufferStart >= REMOTEXYCOMM_BLEDEVICE__RECEIVE_BUFFER_SIZE) receiveBufferStart=0; 126 | } 127 | } 128 | receiveBufferLook=0; 129 | } 130 | } 131 | 132 | /* 133 | // this works already after the buffer overflow and about 100 bytes are lost 134 | void onStatus (BLECharacteristic *pCharacteristic, Status s, uint32_t code) { 135 | if (s == Status::SUCCESS_NOTIFY) canWrite = 1; 136 | } 137 | */ 138 | 139 | void startWrite (uint16_t len) override { 140 | sendBytesAvailable = len; 141 | sendBufferCount = 0; 142 | sendCount = 0; 143 | sendBLEBufferOverflow = 0; 144 | } 145 | 146 | 147 | void write (uint8_t b) override { 148 | // the ESP BLE library have some error 149 | // it has some sent buffer which can overflow after 600 bytes if sending bytes without delay 150 | // as a result of the tests, it was found that 5 ms per 20 bytes are needed 151 | // but if send without delay, it can send up to 600 bytes 152 | 153 | sendBuffer[sendBufferCount++] = b; 154 | sendBytesAvailable--; 155 | if ((sendBufferCount == REMOTEXYCOMM_BLEDEVICE__SEND_BUFFER_SIZE) || (sendBytesAvailable == 0)) { 156 | pRxTxCharacteristic->setValue((uint8_t *)sendBuffer, sendBufferCount); 157 | pRxTxCharacteristic->notify(); 158 | sendCount += sendBufferCount; 159 | sendBufferCount = 0; 160 | if (sendCount >= REMOTEXYCOMM_BLEDEVICE__SEND_BYTES_BEFORE_OVERFLOW) { 161 | if (sendBLEBufferOverflow == 0) { 162 | delay (REMOTEXYCOMM_BLEDEVICE__SEND_BYTES_BEFORE_OVERFLOW / REMOTEXYCOMM_BLEDEVICE__SEND_BUFFER_SIZE * REMOTEXYCOMM_BLEDEVICE__SEND_TIME_FOR_ONE_PACKAGE); 163 | sendBLEBufferOverflow = 1; 164 | } 165 | delay (REMOTEXYCOMM_BLEDEVICE__SEND_TIME_FOR_ONE_PACKAGE); 166 | } 167 | } 168 | } 169 | 170 | void handler () override { 171 | if (receiveBufferCount>0) { 172 | while (receiveBufferLook!=0) { delay(1); } 173 | receiveBufferLook=1; 174 | while (receiveBufferCount) { 175 | notifyReadByteListener (receiveBuffer[receiveBufferStart++]); 176 | if (receiveBufferStart >= REMOTEXYCOMM_BLEDEVICE__RECEIVE_BUFFER_SIZE) receiveBufferStart=0; 177 | receiveBufferCount--; 178 | } 179 | receiveBufferLook=0; 180 | } 181 | } 182 | 183 | 184 | 185 | }; 186 | 187 | #endif // MAIN_BLEDevice_H_ 188 | #endif // RemoteXYStream_BLEDevice_h -------------------------------------------------------------------------------- /src/RemoteXYStream_BLEPeripheral.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYStream_BLEPeripheral_h 2 | #define RemoteXYStream_BLEPeripheral_h 3 | 4 | #if defined(_BLE_PERIPHERAL_H_) 5 | 6 | #include "RemoteXYStream.h" 7 | 8 | #define REMOTEXYCOMM_BLEPERIPHERAL__SEND_BUFFER_SIZE BLE_ATTRIBUTE_MAX_VALUE_LENGTH 9 | #define REMOTEXYCOMM_BLEPERIPHERAL__RECEIVE_BUFFER_SIZE 1024 10 | #define REMOTEXYCOMM_BLEPERIPHERAL__SERVICE_UUID "0000FFE0-0000-1000-8000-00805F9B34FB" // UART service UUID 11 | #define REMOTEXYCOMM_BLEPERIPHERAL__CHARACTERISTIC_UUID "0000FFE1-0000-1000-8000-00805F9B34FB" 12 | //#define REMOTEXYCOMM_BLEPERIPHERAL__DESCRIPTOR_UUID "2902" 13 | 14 | #define REMOTEXYCOMM_BLEPERIPHERAL__CANNOTIFY_TIMEOUT 1000 15 | 16 | class CRemoteXYStream_BLEPeripheral : public CRemoteXYStream, public BLEPeripheral { 17 | 18 | private: 19 | BLEService *pService; 20 | BLECharacteristic *pCharacteristic; 21 | BLEDescriptor *pDescriptor; 22 | 23 | uint8_t sendBuffer[REMOTEXYCOMM_BLEPERIPHERAL__SEND_BUFFER_SIZE]; 24 | uint16_t sendBufferCount; 25 | uint16_t sendBytesAvailable; 26 | 27 | uint8_t receiveBuffer[REMOTEXYCOMM_BLEPERIPHERAL__RECEIVE_BUFFER_SIZE]; 28 | uint16_t receiveBufferStart; 29 | uint16_t receiveBufferPos; 30 | uint16_t receiveBufferCount; 31 | 32 | 33 | public: 34 | CRemoteXYStream_BLEPeripheral (const char * _bleDeviceName) : CRemoteXYStream (), BLEPeripheral () { 35 | #if defined(REMOTEXY__DEBUGLOG) 36 | RemoteXYDebugLog.write("Init NRF BLE on chip"); 37 | #endif 38 | 39 | receiveBufferCount = 0; 40 | receiveBufferStart = 0; 41 | receiveBufferPos = 0; 42 | receiveBufferCount = 0; 43 | 44 | pService = new BLEService (REMOTEXYCOMM_BLEPERIPHERAL__SERVICE_UUID); 45 | pCharacteristic = new BLECharacteristic( REMOTEXYCOMM_BLEPERIPHERAL__CHARACTERISTIC_UUID, BLERead | BLEWriteWithoutResponse | BLENotify, BLE_ATTRIBUTE_MAX_VALUE_LENGTH); 46 | //pDescriptor = new BLEDescriptor(REMOTEXYCOMM_BLEPERIPHERAL__DESCRIPTOR_UUID); 47 | 48 | setLocalName(_bleDeviceName); 49 | setDeviceName(_bleDeviceName); 50 | setAdvertisedServiceUuid (pService->uuid()); 51 | setAppearance(0x0080); 52 | 53 | addAttribute (*pService); 54 | addAttribute (*pCharacteristic); 55 | //addAttribute (*pDescriptor); 56 | 57 | pCharacteristic->setValue(0); 58 | begin(); 59 | 60 | #if defined(REMOTEXY__DEBUGLOG) 61 | RemoteXYDebugLog.write("BLE started"); 62 | #endif 63 | 64 | } 65 | 66 | 67 | void BLEDeviceConnected(BLEDevice& device, const unsigned char* address) override { 68 | #if defined(REMOTEXY__DEBUGLOG) 69 | RemoteXYDebugLog.write("BLE client connected"); 70 | #endif 71 | receiveBufferStart = 0; 72 | receiveBufferPos = 0; 73 | receiveBufferCount = 0; 74 | } 75 | 76 | void BLEDeviceDisconnected(BLEDevice& device) { 77 | #if defined(REMOTEXY__DEBUGLOG) 78 | RemoteXYDebugLog.write("BLE client disconnected"); 79 | #endif 80 | receiveBufferCount = 0; 81 | } 82 | 83 | void BLEDeviceCharacteristicValueChanged (BLEDevice& device, BLECharacteristic& characteristic, const unsigned char* data, unsigned char size) override { 84 | 85 | for (uint16_t i = 0; i < size; i++) { 86 | receiveBuffer[receiveBufferPos++] = data[i]; 87 | if (receiveBufferPos >= REMOTEXYCOMM_BLEPERIPHERAL__RECEIVE_BUFFER_SIZE) receiveBufferPos=0; 88 | if (receiveBufferCount < REMOTEXYCOMM_BLEPERIPHERAL__RECEIVE_BUFFER_SIZE) receiveBufferCount++; 89 | else { 90 | receiveBufferStart++; 91 | if (receiveBufferStart >= REMOTEXYCOMM_BLEPERIPHERAL__RECEIVE_BUFFER_SIZE) receiveBufferStart=0; 92 | } 93 | } 94 | 95 | } 96 | 97 | 98 | void startWrite (uint16_t len) override { 99 | sendBytesAvailable = len; 100 | sendBufferCount = 0; 101 | } 102 | 103 | void write (uint8_t b) override { 104 | if (pCharacteristic->subscribed() == false) { 105 | #if defined(REMOTEXY__DEBUGLOG) 106 | RemoteXYDebugLog.write("BLE: tx characteristic not subscribed"); 107 | #endif 108 | return; 109 | } 110 | sendBuffer[sendBufferCount++] = b; 111 | sendBytesAvailable--; 112 | if ((sendBufferCount == REMOTEXYCOMM_BLEPERIPHERAL__SEND_BUFFER_SIZE) || (sendBytesAvailable == 0)) { 113 | uint32_t t = millis (); 114 | while (pCharacteristic->canNotify () == 0) { 115 | if (millis () - t > REMOTEXYCOMM_BLEPERIPHERAL__CANNOTIFY_TIMEOUT) break; 116 | poll(); 117 | } 118 | pCharacteristic->setValue(sendBuffer, sendBufferCount); 119 | poll(); 120 | sendBufferCount = 0; 121 | 122 | } 123 | } 124 | 125 | void handler () override { 126 | uint8_t b; 127 | BLEPeripheral::poll(); 128 | while (receiveBufferCount > 0) { 129 | b = receiveBuffer[receiveBufferStart++]; 130 | if (receiveBufferStart >= REMOTEXYCOMM_BLEPERIPHERAL__RECEIVE_BUFFER_SIZE) receiveBufferStart=0; 131 | receiveBufferCount--; 132 | notifyReadByteListener (b); 133 | } 134 | } 135 | }; 136 | 137 | 138 | 139 | 140 | 141 | #endif // _BLE_PERIPHERAL_H_ 142 | 143 | #endif //RemoteXYStream_BLEPeripheral_h -------------------------------------------------------------------------------- /src/RemoteXYStream_BluetoothSerial.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYStream_BluetoothSerial_h 2 | #define RemoteXYStream_BluetoothSerial_h 3 | 4 | #if defined (BluetoothSerial_h) || defined (_BLUETOOTH_SERIAL_H_) 5 | 6 | #include "RemoteXYStream_Stream.h" 7 | 8 | 9 | class CRemoteXYStream_BluetoothSerial : public CRemoteXYStream_Stream { 10 | 11 | public: 12 | CRemoteXYStream_BluetoothSerial (const char * _bleDeviceName) : CRemoteXYStream_Stream () { 13 | BluetoothSerial *serial = new BluetoothSerial (); 14 | serial->begin (_bleDeviceName); 15 | setStream (serial); 16 | #if defined(REMOTEXY__DEBUGLOG) 17 | RemoteXYDebugLog.write("Init bluetooth serial: "); 18 | RemoteXYDebugLog.writeAdd(_bleDeviceName); 19 | #endif 20 | } 21 | 22 | }; 23 | 24 | #endif // BluetoothSerial_h _BLUETOOTH_SERIAL_H_ 25 | #endif //RemoteXYStream_BluetoothSerial_h -------------------------------------------------------------------------------- /src/RemoteXYStream_HardSerial.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYStream_HardSerial_h 2 | #define RemoteXYStream_HardSerial_h 3 | 4 | #include "RemoteXYStream_Stream.h" 5 | 6 | 7 | class CRemoteXYStream_HardSerial : public CRemoteXYStream_Stream { 8 | 9 | public: 10 | CRemoteXYStream_HardSerial (HardwareSerial * _serial, long _serialSpeed) : CRemoteXYStream_Stream () { 11 | _serial->begin (_serialSpeed); 12 | setStream (_serial); 13 | #if defined(REMOTEXY__DEBUGLOG) 14 | RemoteXYDebugLog.write("Init hardware serial "); 15 | RemoteXYDebugLog.writeAdd(_serialSpeed); 16 | RemoteXYDebugLog.writeAdd(" baud"); 17 | #endif 18 | } 19 | 20 | }; 21 | 22 | 23 | #endif //RemoteXYStream_HardSerial_h -------------------------------------------------------------------------------- /src/RemoteXYStream_SoftSerial.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYStream_SoftSerial_h 2 | #define RemoteXYStream_SoftSerial_h 3 | 4 | 5 | // if not defined SoftwareSerial.h 6 | #if defined(REMOTEXY_MODE__SOFTSERIAL) || defined(REMOTEXY_MODE__ESP8266_SOFTSERIAL_POINT) || defined(REMOTEXY_MODE__SOFTSERIAL_ESP8266) || defined(REMOTEXY_MODE__SOFTSERIAL_ESP8266_CLOUD) 7 | #if !defined (SoftwareSerial_h) && !defined(SoftSerial_h) 8 | #include "SoftwareSerial.h" 9 | #endif 10 | #endif 11 | 12 | 13 | #if defined(SoftwareSerial_h) || defined(__SoftwareSerial_h) || defined(__SOFTWARE_SERIAL_H__) 14 | #define RemoteXYStream_SoftSerial_T SoftwareSerial 15 | #elif defined(SoftSerial_h) 16 | #define RemoteXYStream_SoftSerial_T SoftSerial 17 | #endif 18 | 19 | 20 | 21 | #if defined(RemoteXYStream_SoftSerial_T) 22 | 23 | #include "RemoteXYStream_Stream.h" 24 | 25 | 26 | class CRemoteXYStream_SoftSerial : public CRemoteXYStream_Stream { 27 | 28 | public: 29 | CRemoteXYStream_SoftSerial (uint8_t _serialRx, uint8_t _serialTx, long _serialSpeed) : CRemoteXYStream_Stream () { 30 | RemoteXYStream_SoftSerial_T * serial = new RemoteXYStream_SoftSerial_T (_serialRx, _serialTx); 31 | serial->begin (_serialSpeed); 32 | setStream (serial); 33 | #if defined(REMOTEXY__DEBUGLOG) 34 | RemoteXYDebugLog.write("Init software serial "); 35 | RemoteXYDebugLog.writeAdd(_serialSpeed); 36 | RemoteXYDebugLog.writeAdd(" baud"); 37 | RemoteXYDebugLog.write("pin RX="); 38 | RemoteXYDebugLog.writeAdd(_serialRx); 39 | RemoteXYDebugLog.writeAdd("; pin TX="); 40 | RemoteXYDebugLog.writeAdd(_serialTx); 41 | #endif 42 | } 43 | 44 | }; 45 | 46 | 47 | #endif // RemoteXYStream_SoftSerial_T 48 | 49 | #endif //RemoteXYStream_SoftSerial_h -------------------------------------------------------------------------------- /src/RemoteXYStream_Stream.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYStream_Stream_h 2 | #define RemoteXYStream_Stream_h 3 | 4 | #include 5 | 6 | // This class allows you to connect 7 | // any communication method that is inherited from the stream class (stream.h) 8 | // Your stream class should define methods: 9 | // int available () 10 | // int read () 11 | // write (uint8_t) 12 | // You must initialize and configure the stream yourself 13 | 14 | #include "RemoteXYComm.h" 15 | 16 | 17 | class CRemoteXYStream_Stream : public CRemoteXYStream { 18 | protected: 19 | Stream * stream; 20 | 21 | public: 22 | CRemoteXYStream_Stream (Stream * _stream) : CRemoteXYStream () { 23 | stream = _stream; 24 | #if defined(REMOTEXY__DEBUGLOG) 25 | RemoteXYDebugLog.write("Init stream"); 26 | #endif 27 | } 28 | 29 | protected: 30 | CRemoteXYStream_Stream () : CRemoteXYStream () { 31 | // use setStream to set stream 32 | } 33 | 34 | 35 | protected: 36 | void setStream (Stream * _stream) { 37 | stream = _stream; 38 | } 39 | 40 | 41 | void handler () override { 42 | while (stream->available ()) notifyReadByteListener (stream->read ()); 43 | } 44 | 45 | void write (uint8_t byte) override { 46 | stream->write (byte); 47 | } 48 | 49 | 50 | }; 51 | 52 | 53 | 54 | #endif //RemoteXYStream_Stream_h -------------------------------------------------------------------------------- /src/RemoteXYStream_USBSerial.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYStream_USBSerial_h 2 | #define RemoteXYStream_USBSerial_h 3 | 4 | 5 | #if defined(USBCON) 6 | #define RemoteXYStream_USBSerial_T Serial_ 7 | #elif defined(_WIRISH_USB_SERIAL_H_) 8 | #define RemoteXYStream_USBSerial_T USBSerial 9 | #elif defined(ARDUINO_UNOR4_MINIMA) || defined(ARDUINO_UNOR4_WIFI) 10 | #define RemoteXYStream_USBSerial_T _SerialUSB 11 | #endif 12 | 13 | #if defined(RemoteXYStream_USBSerial_T) 14 | 15 | 16 | #include "RemoteXYStream_Stream.h" 17 | 18 | 19 | class CRemoteXYStream_USBSerial : public CRemoteXYStream_Stream { 20 | 21 | public: 22 | CRemoteXYStream_USBSerial (RemoteXYStream_USBSerial_T * _serial, long _serialSpeed) : CRemoteXYStream_Stream () { 23 | _serial->begin (_serialSpeed); 24 | setStream (_serial); 25 | #if defined(REMOTEXY__DEBUGLOG) 26 | RemoteXYDebugLog.write("Init USB CDC serial "); 27 | RemoteXYDebugLog.writeAdd(_serialSpeed); 28 | RemoteXYDebugLog.writeAdd(" baud"); 29 | #endif 30 | } 31 | 32 | }; 33 | 34 | 35 | #endif //RemoteXYStream_USBSerial_Type 36 | 37 | #endif //RemoteXYStream_USBSerial_h -------------------------------------------------------------------------------- /src/RemoteXYThread.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYThread_h 2 | #define RemoteXYThread_h 3 | 4 | 5 | #include "RemoteXYApiData.h" 6 | #include "RemoteXYComm.h" 7 | #include "RemoteXYConnection.h" 8 | #include "RemoteXYWire.h" 9 | 10 | 11 | #define REMOTEXY_INIT_CRC 0xffff 12 | #define REMOTEXY_PACKAGE_START_BYTE 0x55 13 | #define REMOTEXY_THREAD_TIMEOUT 8000 14 | 15 | 16 | class CRemoteXYThread : public CRemoteXYReceivePackageListener { 17 | 18 | public: 19 | CRemoteXYThread * next; 20 | 21 | private: 22 | CRemoteXYData* data; 23 | CRemoteXYConnection* conn; 24 | CRemoteXYWire * wire; 25 | 26 | uint8_t *inputVar; 27 | 28 | uint32_t timeOut; 29 | uint8_t stopByTimeOut; 30 | 31 | uint8_t inputVarNeedSend; 32 | 33 | 34 | public: 35 | uint8_t connect_flag; 36 | 37 | public: 38 | CRemoteXYThread (CRemoteXYData * _data) { 39 | 40 | data = _data; 41 | wire = NULL; 42 | 43 | inputVar = (uint8_t*)malloc (data->inputLength); 44 | copyInputVars (); 45 | } 46 | 47 | 48 | 49 | public: 50 | void begin (CRemoteXYConnection * _conn, CRemoteXYWire * _wire, uint8_t _stopByTimeOut) { 51 | conn = _conn; 52 | wire = _wire; 53 | wire->setReceivePackageListener (this); 54 | stopByTimeOut = _stopByTimeOut; 55 | timeOut = millis (); 56 | connect_flag = 0; 57 | 58 | #if defined(REMOTEXY__DEBUGLOG) 59 | RemoteXYDebugLog.write("Client started"); 60 | //RemoteXYDebugLog.writeAvailableMemory (); 61 | #endif 62 | } 63 | 64 | 65 | public: 66 | void stop () { 67 | if (wire) { 68 | conn->stopThreadListener (wire); 69 | wire = NULL; 70 | connect_flag = 0; 71 | #if defined(REMOTEXY__DEBUGLOG) 72 | RemoteXYDebugLog.write("Client stoped"); 73 | #endif 74 | } 75 | } 76 | 77 | public: 78 | uint8_t running () { 79 | if (wire) return 1; 80 | return 0; 81 | } 82 | 83 | 84 | public: 85 | void receivePackage (CRemoteXYPackage * package) override { 86 | uint16_t i, length; 87 | uint8_t *p, *kp, *ip; 88 | uint8_t allowAccess; 89 | 90 | if (wire == NULL) return; 91 | if ((package->command != 0x00) && (!connect_flag)) return; 92 | switch (package->command) { 93 | case 0x00: 94 | allowAccess = 0; 95 | if (package->length==0) { 96 | if (data->accessPassword == NULL) allowAccess=1; 97 | else if (*data->accessPassword == 0) allowAccess=1; 98 | } 99 | else { 100 | if (data->accessPassword != NULL) { 101 | uint8_t ch; 102 | allowAccess = 1; 103 | p = package->buffer; 104 | kp = data->accessPassword; 105 | while (true) { 106 | ch=*kp++; 107 | if (ch!=*p++) allowAccess=0; 108 | if (!ch) break; 109 | } 110 | } 111 | } 112 | if (allowAccess!=0) { 113 | wire->sendPackage (0x00, data->conf, data->confLength, 1); 114 | connect_flag = 1; 115 | } 116 | else { 117 | uint8_t buf[4]; 118 | p = buf; 119 | kp = data->conf; 120 | i=data->confVersion>=5?3:2; 121 | length = i+1; 122 | while (i--) *p++ = data->getConfByte(kp++); 123 | *p++ = 0xf0; 124 | wire->sendPackage (0x00, buf, length, 0); 125 | } 126 | break; 127 | case 0x40: 128 | copyInputVars (); 129 | wire->sendPackage (0x40, data->var, data->inputLength + data->outputLength, 0); 130 | break; 131 | case 0x80: 132 | checkInputVars (); 133 | if ((package->length == data->inputLength) && (inputVarNeedSend==0)) { 134 | p=package->buffer; 135 | kp=data->var; 136 | ip=inputVar; 137 | i= data->inputLength; 138 | while (i--) *ip++=*kp++=*p++; 139 | } 140 | wire->sendPackage (0x80, 0, 0, 0); 141 | break; 142 | case 0xC0: 143 | checkInputVars (); 144 | uint8_t c; 145 | if (inputVarNeedSend==0) c = 0xC0; 146 | else c = 0xC1; 147 | wire->sendPackage (c, data->var + data->inputLength, data->outputLength, 0); 148 | break; 149 | } 150 | timeOut = millis (); 151 | } 152 | 153 | private: 154 | void copyInputVars () { 155 | inputVarNeedSend = 0; 156 | uint8_t * pc = data->var; 157 | uint8_t * p = inputVar; 158 | uint16_t ilen = data->inputLength; 159 | while (ilen--) *p++ = *pc++; 160 | } 161 | 162 | private: 163 | void checkInputVars () { 164 | if (inputVarNeedSend) return; 165 | uint8_t * pc = data->var; 166 | uint8_t * p = inputVar; 167 | uint16_t ilen = data->inputLength; 168 | while (ilen--) { 169 | if (*p++ != *pc++) { 170 | inputVarNeedSend = 1; 171 | break; 172 | } 173 | } 174 | } 175 | 176 | 177 | 178 | public: 179 | void handler () { 180 | if (wire) { 181 | conn->handleWire (wire); 182 | if (wire->running ()) { 183 | if (millis () - timeOut > REMOTEXY_THREAD_TIMEOUT) { 184 | timeOut = millis (); 185 | connect_flag = 0; 186 | if (stopByTimeOut) stop (); 187 | } 188 | } 189 | else stop (); 190 | } 191 | } 192 | 193 | public: 194 | static void startThread (CRemoteXYData * data, CRemoteXYConnection * conn, CRemoteXYWire * wire, uint8_t stopByTimeOut) { 195 | CRemoteXYThread * pt = data->threads; 196 | while (pt) { 197 | if (!pt->running ()) { 198 | pt->begin (conn, wire, stopByTimeOut); 199 | return; 200 | } 201 | pt = pt->next; 202 | } 203 | pt = new CRemoteXYThread (data); 204 | pt->next = data->threads; 205 | data->threads = pt; 206 | pt->begin (conn, wire, stopByTimeOut); 207 | } 208 | 209 | public: 210 | static uint8_t runningCount (CRemoteXYData * data) { 211 | uint8_t c = 0; 212 | CRemoteXYThread * pt = data->threads; 213 | while (pt) { 214 | if (pt->running ()) c++; 215 | pt = pt->next; 216 | } 217 | return c; 218 | } 219 | 220 | }; 221 | 222 | 223 | #endif //RemoteXYThread_h -------------------------------------------------------------------------------- /src/RemoteXYWire.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYWire_h 2 | #define RemoteXYWire_h 3 | 4 | #include "RemoteXYComm.h" 5 | 6 | #define REMOTEXY_INIT_CRC 0xffff 7 | #define REMOTEXY_PACKAGE_START_BYTE 0x55 8 | #define REMOTEXY_PACKAGE_MIN_LENGTH 6 9 | 10 | 11 | struct CRemoteXYPackage { 12 | uint8_t command; 13 | uint8_t * buffer; 14 | uint16_t length; 15 | }; 16 | 17 | class CRemoteXYReceivePackageListener { 18 | public: 19 | virtual void receivePackage (CRemoteXYPackage * package) = 0; 20 | }; 21 | 22 | class CRemoteXYWire { 23 | 24 | private: 25 | CRemoteXYReceivePackageListener * receivePackageListener; 26 | 27 | public: 28 | CRemoteXYWire () { 29 | receivePackageListener = NULL; 30 | } 31 | 32 | public: 33 | void setReceivePackageListener (CRemoteXYReceivePackageListener * listener) { 34 | receivePackageListener = listener; 35 | } 36 | 37 | public: 38 | void notifyReceivePackageListener (CRemoteXYPackage * package) { 39 | if (receivePackageListener) receivePackageListener->receivePackage (package); 40 | } 41 | 42 | 43 | public: 44 | virtual void handler () {}; 45 | virtual uint8_t running () {return 0;}; 46 | virtual void stop () {}; 47 | virtual void sendPackage (uint8_t command, uint8_t *buf, uint16_t length, uint8_t fromPgm) {UNUSED (command); UNUSED (buf); UNUSED (length); UNUSED (fromPgm);}; 48 | 49 | }; 50 | 51 | 52 | #endif // RemoteXYWire_h -------------------------------------------------------------------------------- /src/RemoteXYWireCloud.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYWireCloud_h 2 | #define RemoteXYWireCloud_h 3 | 4 | #include "RemoteXYWire.h" 5 | 6 | 7 | #define REMOTEXYWIRECLOUD_FREE_ID 0xff 8 | 9 | 10 | class CRemoteXYSendPackageListener { 11 | public: 12 | virtual void sendPackage (uint8_t command, uint8_t *buf, uint16_t length, uint8_t fromPgm) = 0; 13 | }; 14 | 15 | class CRemoteXYWireCloud: public CRemoteXYWire { 16 | 17 | public: 18 | CRemoteXYWireCloud * next; 19 | uint8_t id; // 0..7 20 | uint8_t newConnection; 21 | 22 | private: 23 | CRemoteXYSendPackageListener * sendPackageListener; 24 | 25 | public: 26 | CRemoteXYWireCloud (CRemoteXYSendPackageListener * _sendPackageListener) : CRemoteXYWire () { 27 | sendPackageListener = _sendPackageListener; 28 | id = REMOTEXYWIRECLOUD_FREE_ID; 29 | newConnection = 0; 30 | } 31 | 32 | public: 33 | void init (uint8_t _id) { 34 | id = _id; 35 | newConnection = 1; 36 | } 37 | 38 | /* 39 | public: 40 | void begin () { 41 | newConnection = 0; 42 | } 43 | */ 44 | 45 | public: 46 | void stop () override { 47 | setReceivePackageListener (NULL); 48 | id = REMOTEXYWIRECLOUD_FREE_ID; 49 | newConnection = 0; 50 | } 51 | 52 | public: 53 | uint8_t running () override { 54 | if (id == REMOTEXYWIRECLOUD_FREE_ID) return 0; 55 | return 1; 56 | } 57 | 58 | public: 59 | uint8_t isNewConnection () { 60 | return newConnection; 61 | } 62 | 63 | 64 | public: 65 | void sendPackage (uint8_t command, uint8_t *buf, uint16_t length, uint8_t fromPgm) override { 66 | sendPackageListener->sendPackage (command | (id<<1), buf, length, fromPgm); 67 | } 68 | 69 | 70 | public: 71 | void receivePackage (CRemoteXYPackage * package) { 72 | notifyReceivePackageListener (package); 73 | } 74 | 75 | }; 76 | 77 | #endif //RemoteXYWireCloud_h -------------------------------------------------------------------------------- /src/RemoteXYWireStream.h: -------------------------------------------------------------------------------- 1 | #ifndef RemoteXYWireStream_h 2 | #define RemoteXYWireStream_h 3 | 4 | 5 | #include "RemoteXYWire.h" 6 | #include "RemoteXYApiData.h" 7 | 8 | 9 | class CRemoteXYWireStream : public CRemoteXYWire, public CRemoteXYReadByteListener { 10 | 11 | public: 12 | CRemoteXYWireStream * next; 13 | CRemoteXYStream * stream; 14 | 15 | private: 16 | uint16_t sendCRC; 17 | 18 | uint8_t *receiveBuffer; 19 | uint16_t receiveBufferSize; 20 | uint16_t receiveIndex; 21 | uint8_t receiveModified; 22 | volatile uint8_t receiveLock; // =1 only add to receive buffer 23 | 24 | 25 | public: 26 | CRemoteXYWireStream (CRemoteXYData * data) : CRemoteXYWire () { 27 | stream = NULL; 28 | receiveBufferSize = data->getReceiveBufferSize (); 29 | receiveBuffer = (uint8_t*)malloc (receiveBufferSize); 30 | } 31 | 32 | public: 33 | CRemoteXYWireStream (CRemoteXYData * data, uint8_t multiple) : CRemoteXYWire () { 34 | stream = NULL; 35 | receiveBufferSize = data->getReceiveBufferSize () * multiple; 36 | receiveBuffer = (uint8_t*)malloc (receiveBufferSize); 37 | } 38 | 39 | public: 40 | void begin (CRemoteXYStream * _stream) { 41 | stream = _stream; 42 | stream->setReadByteListener (this); 43 | receiveIndex = 0; 44 | receiveModified = 0; 45 | receiveLock = 0; 46 | } 47 | 48 | public: 49 | void stop () override { 50 | setReceivePackageListener (NULL); 51 | stream = NULL; 52 | } 53 | 54 | public: 55 | uint8_t running () override { 56 | if (stream) return 1; 57 | else return 0; 58 | } 59 | 60 | CRemoteXYClient * getClient () { 61 | return (CRemoteXYClient*)stream; 62 | } 63 | 64 | 65 | 66 | public: 67 | void handler () override { 68 | if (stream) { 69 | stream->handler (); 70 | receivePackage (); 71 | } 72 | } 73 | 74 | 75 | private: 76 | void updateCRC (uint16_t *crc, uint8_t b) { 77 | *crc ^= b; 78 | for (uint8_t i=0; i<8; ++i) { 79 | if ((*crc) & 1) *crc = ((*crc) >> 1) ^ 0xA001; 80 | else *crc >>= 1; 81 | } 82 | } 83 | 84 | 85 | private: 86 | inline void sendByteUpdateCRC (uint8_t b) { 87 | #if defined(REMOTEXY__DEBUGLOG) 88 | RemoteXYDebugLog.writeOutputHex (b); 89 | #endif 90 | stream->write (b); 91 | updateCRC (&sendCRC, b); 92 | } 93 | 94 | 95 | public: 96 | void sendPackage (uint8_t command, uint8_t *buf, uint16_t length, uint8_t fromPgm) { 97 | uint16_t packageLength; 98 | if (stream) { 99 | sendCRC = REMOTEXY_INIT_CRC; 100 | packageLength = length+6; 101 | stream->startWrite (packageLength); 102 | 103 | sendByteUpdateCRC (REMOTEXY_PACKAGE_START_BYTE); 104 | sendByteUpdateCRC (packageLength); 105 | sendByteUpdateCRC (packageLength>>8); 106 | sendByteUpdateCRC (command); 107 | uint8_t b; 108 | while (length--) { 109 | if (fromPgm) b=pgm_read_byte_near (buf++); 110 | else b=*buf++; 111 | sendByteUpdateCRC (b); 112 | } 113 | #if defined(REMOTEXY__DEBUGLOG) 114 | RemoteXYDebugLog.writeOutputHex (sendCRC); 115 | RemoteXYDebugLog.writeOutputHex (sendCRC>>8); 116 | #endif 117 | stream->write (sendCRC); 118 | stream->write (sendCRC>>8); 119 | } 120 | } 121 | 122 | public: 123 | void readByte (uint8_t byte) override { 124 | uint16_t pi, i; 125 | 126 | #if defined(REMOTEXY__DEBUGLOG) 127 | RemoteXYDebugLog.writeInputHex (byte); 128 | #endif 129 | if ((receiveIndex==0) && (byte!=REMOTEXY_PACKAGE_START_BYTE)) return; 130 | if (receiveIndex >= receiveBufferSize) { 131 | if (receiveLock) return; 132 | pi = 1; 133 | while (pi < receiveBufferSize) { 134 | if (receiveBuffer[pi] == REMOTEXY_PACKAGE_START_BYTE) break; 135 | pi++; 136 | } 137 | receiveIndex = receiveBufferSize - pi; 138 | i=0; 139 | while (pi < receiveBufferSize) receiveBuffer[i++] = receiveBuffer[pi++]; 140 | } 141 | receiveBuffer[receiveIndex++]=byte; 142 | receiveModified = 1; 143 | } 144 | 145 | private: 146 | void receivePackage () { 147 | if (receiveModified) { 148 | receiveModified = 0; 149 | 150 | uint16_t crc; 151 | uint16_t si, i; 152 | uint16_t packageLength; 153 | si = 0; 154 | while (si + REMOTEXY_PACKAGE_MIN_LENGTH <= receiveIndex) { 155 | if (receiveBuffer[si] == REMOTEXY_PACKAGE_START_BYTE) { 156 | packageLength = receiveBuffer[si+1]|(receiveBuffer[si+2]<<8); 157 | if ((packageLength <= receiveIndex - si) && (packageLength >=6)) { 158 | crc=REMOTEXY_INIT_CRC; 159 | for (i = si; i < si + packageLength; i++) updateCRC (&crc, receiveBuffer[i]); 160 | if (crc == 0) { 161 | CRemoteXYPackage package; 162 | package.command = receiveBuffer[si+3]; 163 | package.buffer = receiveBuffer+si+4; 164 | package.length = packageLength-6; 165 | 166 | receiveLock = 1; 167 | notifyReceivePackageListener (&package); 168 | si += packageLength; 169 | i = 0; 170 | while (si < receiveIndex) receiveBuffer[i++] = receiveBuffer[si++]; 171 | receiveIndex = i; 172 | receiveLock = 0; 173 | si = 0; 174 | continue; 175 | } 176 | } 177 | } 178 | si++; 179 | } 180 | } 181 | } 182 | 183 | }; 184 | 185 | 186 | #endif // RemoteXYWireStream_h --------------------------------------------------------------------------------