-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConstantCurrent.ino
105 lines (70 loc) · 3.18 KB
/
ConstantCurrent.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "variables.h"
WiFiClient espClient;
PubSubClient client(espClient);
INA219 ina219;
//*****************************************************************************************************************************************
//**************************************************************Subroutines****************************************************************
//*****************************************************************************************************************************************
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||END Subroutines****************************************************************
// s e t u p ( )
//**********************************************************************
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("******************");
Serial.print("Begining setup..");
delay(10);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, ledState); // turn the LED off, internal LED connected to high
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi..");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.print("Connected to the WiFi network - ");
//Serial.println(WiFi.available());
Serial.println(WiFi.status());
client.setServer(mqttServer, mqttPort);
client.setCallback(callback);
while (!client.connected()) {
Serial.println("Connecting to MQTT...");
if (client.connect("ESP8266Client", mqttUser, mqttPassword )) {
Serial.println("connected");
delay(50);
sendMQTT("esp/text", "Booting");
} else {
Serial.print("failed with state ");
Serial.println(client.state());
delay(100);
}
}
client.publish("esp/text", "ESP8266 started");
client.subscribe("esp/control");
client.subscribe("esp/controlcurrent");
ina219.begin();
// begin calls:
// configure() with default values RANGE_32V, GAIN_8_320MV, ADC_12BIT, ADC_12BIT, CONT_SH_BUS
// calibrate() with default values D_SHUNT=0.1, D_V_BUS_MAX=32, D_V_SHUNT_MAX=0.2, D_I_MAX_EXPECTED=2
// in order to work directly with ADAFruit's INA219B breakout
//ina219.configure(INA219::RANGE_16V, INA219::GAIN_2_80MV, INA219::ADC_128SAMP, INA219::ADC_128SAMP, INA219::CONT_SH_BUS);
//ina219.configure(INA219::ADC_128SAMP);
pinMode(pwmPin, OUTPUT);
digitalWrite(pwmPin, LOW);
// Blink LED
blinkLED(3, 400);
}
// E n d o f s e t u p ( )
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//*****************************************************************************************************************************************
//**************************************************************MAIN LOOP******************************************************************
//*****************************************************************************************************************************************
void loop() {
client.loop();
currentMillis = millis();
current_loop();
send_Data();
blinky();
delay(5);
}
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||END Main Loop**************************************************************