Skip to content

Commit

Permalink
updated fw, circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
Nauman3S committed Dec 4, 2021
1 parent 79143c9 commit 0f5b29e
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 5 deletions.
Binary file modified Circuit/Circuit.fzz
Binary file not shown.
Binary file modified Circuit/Circuit_bb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
4 changes: 4 additions & 0 deletions Firmware/Firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ void setup() //main setup functions

setupBME280();
setupSoilMoisture();
pinMode(R1,OUTPUT);
pinMode(R2,OUTPUT);
pinMode(R3,OUTPUT);

queue = xQueueCreate(1, sizeof(npkData));
if (queue == NULL)
{
Expand Down
50 changes: 46 additions & 4 deletions Firmware/MQTTFuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ void reconnect();
bool mqttConnect();
void mqttPublish(String path, String msg);
int deviceExisits = 0;
IPAddress ip(34,214,65,82);
IPAddress ip(34, 214, 65, 82);
String topicN = String("smart-agri/deviceExistance");
String topicR = ss.getMacAddress() + String("/relay");
String topicS = ss.getMacAddress() + String("/settings");
void MQTTUnSubscribe()
{
String topicN = String("smart-agri/deviceExistance");
// String topicN = String("smart-agri/deviceExistance");
// String topicR = ss.getMacAddress() + String("/relay");
// String topicS = ss.getMacAddress() + String("/settings");

mqttClient.unsubscribe(topicN.c_str());
mqttClient.unsubscribe(topicR.c_str());
mqttClient.unsubscribe(topicS.c_str());
}
void MQTTSubscriptions()
{
Expand All @@ -19,9 +26,10 @@ void MQTTSubscriptions()
// for(int i=0;i<10;i++){
// IMEIsList[i]==String("NA");
// }
String topicN = String("smart-agri/deviceExistance");

mqttClient.subscribe(topicN.c_str());
mqttClient.subscribe(topicR.c_str());
mqttClient.subscribe(topicS.c_str());
}
void callback(char *topic, byte *payload, unsigned int length)
{
Expand All @@ -48,9 +56,43 @@ void callback(char *topic, byte *payload, unsigned int length)
deviceExisits = 1;
}
}
else if (String(topic) == topicR)
{
if (pLoad.indexOf("1") >= 0)
{
digitalWrite(R1, !digitalRead(R1));
}
if (pLoad.indexOf("2") >= 0)
{
digitalWrite(R2, !digitalRead(R2));
}
if (pLoad.indexOf("3") >= 0)
{
digitalWrite(R3, !digitalRead(R3));
}
}

else if (String(topic) == topicS)
{
if (pLoad.indexOf("soil_sensor=") >= 0)
{
String temp = ss.StringSeparator(pLoad, '=', 1);
String lowV = ss.StringSeparator(temp, ',', 0);
String highV = ss.StringSeparator(temp, ',', 1);
soil_sensorCalibValues[0] = lowV.toInt();
soil_sensorCalibValues[1] = highV.toInt();
}
else if (pLoad.indexOf("device_operation=") >= 0)
{
if (pLoad.indexOf("restart=") >= 0)
{
ESP.reset();
}
}
}

// Switch on the LED if an 1 was received as first character

pLoad = "";
}
void reconnect()
Expand Down
5 changes: 5 additions & 0 deletions Firmware/headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ String apid;
String hostName = "SmartA";
String apPass;
String settingsPass;
#define R1 26
#define R2 25
#define R3 33

int soil_sensorCalibValues[2]={550,0}//low,high

#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
Expand Down
2 changes: 1 addition & 1 deletion Firmware/soilMoistureHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ String getSoilMoisture()
{

value = analogRead(sensor_pin);
value = map(value, 550, 0, 0, 100);
value = map(value, soil_sensorCalibValues[0], soil_sensorCalibValues[1], 0, 100);
Serial.print("Moisture : ");
Serial.print(value);
Serial.println("%");
Expand Down
Binary file removed README.pdf
Binary file not shown.

0 comments on commit 0f5b29e

Please sign in to comment.