Browse Source

Renamed esp8266_ac to esp12e_ac cuz esp8266 is the actual microchip but we designed that shit with the ESP-12E module in mind, added todo shit to main readm3, listed recommended b0ard settings at the top of em sk3tch, adjusted AC button press serv0 p0sish and added prerotate function to check if em serv0 wouldn't go out of bounds ;];];];];]]

Wazakindjes 1 year ago
parent
commit
59a20efd34
3 changed files with 58 additions and 26 deletions
  1. 7 2
      README.md
  2. 10 10
      esp8266_airconditioner/README.md
  3. 41 14
      esp8266_airconditioner/esp8266_airconditioner.ino

+ 7 - 2
README.md

@@ -1,5 +1,10 @@
 # The fuck is this
-This shit is a dankass repository for sharing sketches for use with Arduino-type and compatible microcontrollers (like ESP8266). [=[[=[=[==[[=
+This shit is a dankass repository for sharing sketches for use with Arduino-type and compatible microcontrollers (like ESP8266-based shit). [=[[=[=[==[[=
+
+# Some todo shit
+Just to keep this in a place outside of the actual sketches. ;]
+
+* Look into moving shared custom shit (e.g. netserial) to a library of sorts
 
 # Contrib00tin
 If you wrote some nice haccs then make a pull request and I might merge that shit. ;] Just keep in mind that every sketch should always have its own directory and README file. Said README should include clear information on the setup, but you may assume that people at least know how to do basic things like setting up the IDE and flashing their shit. ;] Some key points:
@@ -10,4 +15,4 @@ If you wrote some nice haccs then make a pull request and I might merge that shi
 * You __don't__ need to include info about the actual application (e.g. putting it all together in a case and all that shit), just assume people are working on breadb0ards
 * The sketch should probably work and compile using the Arduino IDE, as that's likely what people will be using lel
 
-Or just look at mein [esp8266_airconditioner shit](./esp8266_airconditioner) for an indication of the necessary inf0.
+Or just look at mein [esp12e_airconditioner shit](./esp12e_airconditioner) for an indication of the necessary inf0.

+ 10 - 10
esp8266_airconditioner/README.md

@@ -8,7 +8,7 @@ Also, since this was my first real pr0ject for this kind of shit, it has as many
 * HTTPS instead of plain HTTP for the API, __note that this does mean you need to generate a certificate__
 
 # Parts/components:
-* NodeMCU v3 (dev b0ard) w/ ESP8266 onboard
+* NodeMCU v3 (dev b0ard) w/ ESP-12E onboard
 * DS18B20 temperature sensor (I got the waterproof version but the breadboard one should have the same wiring anyways)
 * TS90A analog micro servo motor
 * 3 LEDs: red, green, yellow (see just below for more inf0z)
@@ -63,7 +63,7 @@ While reading the c0dd you may have seen something I call "netserial", which was
 
 When booting up and after getting an IP address, the ESP will automatically calculate the broadcast address for the network it's in and send messages to it. An example message is `[OTA] Starting sketch flash`).
 
-To receive the broadcast I'm using the `ncat` tool from the `nmap` package, which is __a different program than the default netcat__. It has more options and is the only one I found worked reliably in receiving the messages. I simply slammed the following alias in muh `.bash_profile`: `alias netserial-esp8266-ac="ncat --recv-only -u -v -l -C 192.168.133.255 1338"`
+To receive the broadcast I'm using the `ncat` tool from the `nmap` package, which is __a different program than the default netcat__. It has more options and is the only one I found worked reliably in receiving the messages. I simply slammed the following alias in muh `.bash_profile`: `alias netserial-esp8266="ncat --recv-only -u -v -l -C 192.168.133.255 1338"`
 
 # JSON API
 The API works over HTTPS, using POST requests with URL-encoded parameters and resp0nding with JSON. The sketch has the necessary code for reverting back to plain HTTP, I simply added HTTPS for maximum keks. =]
@@ -87,11 +87,11 @@ Since it uses HTTPS, you need to generate a certificate and put em in the config
 ## Testing the API w/ cURL
 Obviously substitute the auth token and URL with the ones you've specified in the config section.
 
-* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=read_temp' https://esp8266-ac:1339/h4x`
-* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=servo_rotate&arg=100' https://esp8266-ac:1339/h4x`
-* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=servo_acbutton' https://esp8266-ac:1339/h4x`
-* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=servo_reset' https://esp8266-ac:1339/h4x`
-* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=led_on&arg=flasher' https://esp8266-ac:1339/h4x`
-* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=led_off&arg=flasher' https://esp8266-ac:1339/h4x`
-* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=reboot' https://esp8266-ac:1339/h4x`
-* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=deepsleep' https://esp8266-ac:1339/h4x`
+* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=read_temp' https://esp12e-ac:1339/h4x`
+* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=servo_rotate&arg=100' https://esp12e-ac:1339/h4x`
+* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=servo_acbutton' https://esp12e-ac:1339/h4x`
+* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=servo_reset' https://esp12e-ac:1339/h4x`
+* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=led_on&arg=flasher' https://esp12e-ac:1339/h4x`
+* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=led_off&arg=flasher' https://esp12e-ac:1339/h4x`
+* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=reboot' https://esp12e-ac:1339/h4x`
+* `curl -k -X POST -H 'X-Bighecks-Auth: ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023' --data 'cmd=deepsleep' https://esp12e-ac:1339/h4x`

+ 41 - 14
esp8266_airconditioner/esp8266_airconditioner.ino

@@ -1,3 +1,26 @@
+/*
+*** ARDUINO IDE BOARD SETTINGS
+*** Cuz apparently there's no easy way to store settings for a certain b0ard, I'll just have to leave it in here for na0 -.-
+***
+*** - Board: Generic ESP8266 Module
+*** - Builtin Led: 2
+*** - Upload Speed: 3000000
+*** - CPU Frequency: 160 MHz
+*** - Crystal Frequency: 26 MHz
+*** - Flash Size: 4 MB (FS: none, OTA: ~1019 kB)
+*** - Flash Mode: DIO
+*** - Flash Frequency: 40 MHz
+*** - Reset Method: dtr (aka nodemcu)
+*** - Debug Port: Disabled
+*** - Debug Level: None
+*** - IwIP Variant: v2 Lower Memory
+*** - VTables: Flash
+*** - Exceptions: Legacy (new can return nullptr)
+*** - Erase Flash: Only Sketch
+*** - Espressif FW: nonos-sdk 2.2.1+100 (190703)
+*** - SSL Support: All SSL ciphers (most compatible)
+*/
+
 #include <ESP8266WiFi.h>
 #include <ArduinoOTA.h>
 //#include <WiFiUdp.h> // ArduinoOTA includes this itself so may not be necessary to specify em separately
@@ -10,7 +33,7 @@
 /*** ========= CONFIG START ========= ***/
 
 /*** SYSTEM ***/
-#define MUHCONF_SYS_HOSTNAME "esp8266-ac" // We'll prolly have multiple ESPs at some point ;];;];];]
+#define MUHCONF_SYS_HOSTNAME "esp12e-ac" // We'll prolly have multiple ESPs at some point ;];;];];]
 #define MUHCONF_SYS_DEEPSLEEP 5 // Wake from deep sleep after 5 minutes (both in case of non-connecting WiFi as well as the API command for it)
 
 /*** WIFI ***/
@@ -38,7 +61,7 @@
 #define MUHCONF_HTTP_POT 1339
 #define MUHCONF_HTTP_HEADER_AUTH "X-Bighecks-Auth"
 #define MUHCONF_HTTP_AUTH_SECRET "ec8534d2ff2917903e6071a6049274b3f0f1516780760d8be78c6b9082521023" // Pass this in le POST request w/ the auth header ;];]
-#define MUHCONF_HTTP_ENDPOINT "/h4x" // Gotta do em POST request to https://esp8266-ac:1339/h4x?cmd=<cmd>&arg=<ARG> (arg is optional kek)
+#define MUHCONF_HTTP_ENDPOINT "/h4x" // Gotta do em POST request to https://esp12e-ac:1339/h4x?cmd=<cmd>&arg=<ARG> (arg is optional kek)
 #define MUHCONF_HTTP_JSON_MAXLEN 128 // Maximum length of JSON response string kek (should be smaller than MUHCONF_NETSERIAL_PRINTF_BUFSIZE because we print the full JSON in case of errors ;]];;];])
 
 #define MUHCONF_HTTP_JSON_ERRCODE_GUCCI 0
@@ -78,7 +101,7 @@
 
 /*** POSITIONS ***/
 #define MUHCONF_POS_SERVO_NEUTRAL 2200
-#define MUHCONF_POS_SERVO_ACBUTTON 960 // Touching the button happens at this point kek
+#define MUHCONF_POS_SERVO_ACBUTTON 760 // Touching the button happens at this point kek
 
 /*** LIMITS ***/
 // First are absolute/hard limits, i.e. the serv0 can't rotate beyond these points without risk of breaking em ;]
@@ -88,9 +111,9 @@ const unsigned short int limits_servo_rotation[2] = {
 	2200 // All the waii around (180 degreez in this case)
 };
 
-// Soft limits depend on where the fuckin thing is mounted, in my case if it would rotate beyond 960 then the servo would push itself (too far) upwards and we don't want dat ;]
+// Soft limits depend on where the fuckin thing is mounted, in my case if it would rotate beyond 920 then the servo would push itself (too far) upwards and we don't want dat ;]
 const unsigned short int softlimits_servo_rotation[2] = {
-	MUHCONF_POS_SERVO_ACBUTTON,
+	720,
 	limits_servo_rotation[1] // Just reuse the max from el hard limits lol
 };
 
@@ -597,19 +620,22 @@ void led_on_error_interval(void) {
 	end_led_error = millis() + MUHCONF_WAIT_LED_ERROR;
 }
 
-void servo_rotate(unsigned short int us) {
+void servo_check_prerotate(unsigned short int *us) {
 	// Check soft limits first lol
-	if(us < softlimits_servo_rotation[0])
-		us = softlimits_servo_rotation[0];
-	else if(us > softlimits_servo_rotation[1])
-		us = softlimits_servo_rotation[1];
+	if(*us < softlimits_servo_rotation[0])
+		*us = softlimits_servo_rotation[0];
+	else if(*us > softlimits_servo_rotation[1])
+		*us = softlimits_servo_rotation[1];
 
 	// Then hard wuns
-	else if(us < limits_servo_rotation[0])
-		us = limits_servo_rotation[0];
-	else if(us > limits_servo_rotation[1])
-		us = limits_servo_rotation[1];
+	else if(*us < limits_servo_rotation[0])
+		*us = limits_servo_rotation[0];
+	else if(*us > limits_servo_rotation[1])
+		*us = limits_servo_rotation[1];
+}
 
+void servo_rotate(unsigned short int us) {
+	servo_check_prerotate(&us);
 	muhservo.writeMicroseconds(us);
 }
 
@@ -703,6 +729,7 @@ void http_handle_cmd(void) {
 			}
 
 			arg_int = arg.toInt();
+			servo_check_prerotate(&arg_int);
 			snprintf(sendbuf, sizeof(sendbuf), "Rotating to %d microseconds", arg_int);
 		}