-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge devel into master -> code base "done" (#4):
* add EndPos library: - to detect if the solar panel is at its "endpostions" * add EndPostion to dependencies in platform.ini and rename endpos files * fix includes in QMC5883L lib * add Wire lib locally * add Wire and change SonnenStand * add library.properties to all libs for better autogen configs * add FindSun lib * add MoveMotors lib *NOT TESTED* * fix EndPos - pinMode to INPUT - read pins in own function keeps being called in loop * fix FindSun - add missing time init - split azimith reading to keep being called in loop * fix MoveMotors - swith LOW and HIGH for powering Motors - make bunch of defines for the code to make sense * fix SunPosition - change floats to ints - init rtc and time once in own function * add example code for RTC * add main.cpp with test code - [x] turn table to find sun - [x] get azimuth and time * add check tilt to FindSun * add final main.cpp ->: - check suns position with kompass and time - check suns angle and adjust according to light intensity - post the data to a django server * comment wifi/webserver settings out for testting * add check rotation * adjust logic -> first rotation then tilt * add comments * add comments and fix typo (#2) explanatory comments to check_tilt * add start pos * uncomment wifi settings, remove test code and add postData - every fifth tick send postData - change server and server port - add rtc_temp_sensor * remove test code/output * add features to main plus fixes Co-authored-by: Johannes Schiessel <[email protected]>
- Loading branch information
Showing
5 changed files
with
292 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,109 @@ | ||
#include <Arduino.h> | ||
#include <EndPos.h> | ||
#include <MoveMotors.h> | ||
#include <SunPosition.h> | ||
#include <RTClib.h> | ||
#include <Wire.h> | ||
#include <FindSun.h> | ||
#include <ESP8266WiFi.h> | ||
|
||
char ssid[] = "ADD_SSID"; | ||
char pass[] = "ADD_PASSWORD"; | ||
int status = WL_IDLE_STATUS; | ||
int check_rotation=1; | ||
char server[] = "arduino.ayhamcloud.de"; | ||
String postData_k; | ||
String postData_d; | ||
String postData; | ||
|
||
WiFiClient client; | ||
int ticks = 0; | ||
int gen_status = 1; | ||
String endpos_val; | ||
int az; | ||
float diode; | ||
int offset; | ||
float temperature; | ||
|
||
RTC_DS3231 rtc_temp_only; | ||
EndPos endPos; | ||
Motor turnTable; | ||
Motor tiltPanel; | ||
SonnenStand sunpos; | ||
Find_Sun FindSun; | ||
|
||
|
||
void setup() | ||
{ | ||
|
||
// put your setup code here, to run once: | ||
Serial.begin(9600); | ||
rtc_temp_only.begin(); | ||
turnTable.init_motor(D0, D3, 1); | ||
tiltPanel.init_motor(D7, D4, 2); | ||
FindSun.init_compass(); | ||
WiFi.begin(ssid, pass); | ||
while (WiFi.status() != WL_CONNECTED) | ||
{ | ||
Serial.println("Attempting to connect to Network named: "); | ||
Serial.println(ssid); | ||
delay(3000); | ||
} | ||
Serial.print("SSID: "); | ||
Serial.println(WiFi.SSID()); | ||
IPAddress ip = WiFi.localIP(); | ||
Serial.print("IP Address: "); | ||
Serial.println(ip); | ||
pinMode(A0, OUTPUT); | ||
FindSun.start_pos(); | ||
} | ||
|
||
void loop() | ||
{ | ||
// put your main code here, to run repeatedly: | ||
} | ||
ticks++; | ||
sunpos.get_azimuth(sunpos.get_arr_pos()); | ||
az = FindSun.get_current_azimuth(); | ||
diode = (analogRead(A0) * 5) / 1024.0; | ||
offset = FindSun.offset_to_Sun(); | ||
temperature = rtc_temp_only.getTemperature(); | ||
|
||
|
||
check_rotation=FindSun.check_rotation(); | ||
|
||
if(check_rotation==0) | ||
FindSun.check_tilt(); | ||
|
||
if(ticks==5) | ||
{ | ||
if(endPos.getPosPhiDown()==0) | ||
endpos_val = "Down"; | ||
else if(endPos.getPosPhiUp()==1) | ||
endpos_val = "Up"; | ||
else | ||
endpos_val = "Tilted"; | ||
|
||
postData = "kompass=" + (String)az; | ||
postData += "&diode=" + (String)diode; | ||
postData += "&offset=" + (String)offset; | ||
postData += "&temperature" + (String)temperature; | ||
postData += "&endpost=" + (String)endpos_val; | ||
postData += "&status=" + (String)gen_status; | ||
postData += "&tiltPanel=" + (String)tiltPanel.get_rot(); | ||
postData += "&turnTable=" + (String)turnTable.get_rot(); | ||
|
||
if (client.connect(server, 80)) | ||
{ | ||
client.println("POST / HTTP/1.1"); | ||
client.println("Content-Type: application/x-www-form-urlencoded"); | ||
client.print("Content-Length: "); | ||
client.println(postData.length()); | ||
client.println(); | ||
client.print(postData); | ||
} | ||
if (client.connected()) | ||
{ | ||
client.stop(); | ||
} | ||
ticks = 0; | ||
delay(100); | ||
} | ||
gen_status = 0; | ||
} |
Oops, something went wrong.