Spaces:
Running
Running
Add 1 files
Browse files- index.html +813 -843
index.html
CHANGED
|
@@ -1,899 +1,869 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
-
<html
|
| 3 |
<head>
|
| 4 |
-
<
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>AgriChain | Smart Farming 4.0</title>
|
| 7 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
-
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 10 |
-
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
|
| 11 |
<style>
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
--dark: #1f2937;
|
| 18 |
-
--light: #f9fafb;
|
| 19 |
}
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
.dashboard-card {
|
| 27 |
-
transition: all 0.3s ease;
|
| 28 |
-
border-left: 4px solid var(--primary);
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
.dashboard-card:hover {
|
| 32 |
-
transform: translateY(-5px);
|
| 33 |
-
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
.iot-node {
|
| 37 |
-
animation: pulse 2s infinite;
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
@keyframes pulse {
|
| 41 |
-
0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
|
| 42 |
-
70% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
|
| 43 |
-
100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
.blockchain-block {
|
| 47 |
-
border-top: 3px solid var(--primary);
|
| 48 |
-
transition: all 0.3s ease;
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
.blockchain-block:hover {
|
| 52 |
-
transform: scale(1.02);
|
| 53 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
.ai-prediction-card {
|
| 57 |
-
background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
.sensor-grid {
|
| 61 |
-
display: grid;
|
| 62 |
-
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
|
| 63 |
-
gap: 1rem;
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
.protocol-badge {
|
| 67 |
-
font-size: 0.7rem;
|
| 68 |
-
padding: 0.2rem 0.5rem;
|
| 69 |
-
border-radius: 1rem;
|
| 70 |
}
|
| 71 |
</style>
|
| 72 |
</head>
|
| 73 |
-
<body>
|
| 74 |
-
<div class="
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
<
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
<a href="#" class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">IoT Network</a>
|
| 87 |
-
<a href="#" class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">AI Predictions</a>
|
| 88 |
-
<a href="#" class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">Blockchain</a>
|
| 89 |
-
<a href="#" class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">Settings</a>
|
| 90 |
-
</div>
|
| 91 |
-
</div>
|
| 92 |
-
<div class="hidden sm:ml-6 sm:flex sm:items-center">
|
| 93 |
-
<div class="relative">
|
| 94 |
-
<div class="flex space-x-4">
|
| 95 |
-
<button class="bg-white p-1 rounded-full text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-emerald-500 relative">
|
| 96 |
-
<i class="fas fa-network-wired h-6 w-6"></i>
|
| 97 |
-
<span class="absolute -top-1 -right-1 h-3 w-3 rounded-full bg-green-500 animate-ping"></span>
|
| 98 |
-
<span class="absolute -top-1 -right-1 h-3 w-3 rounded-full bg-green-500"></span>
|
| 99 |
-
</button>
|
| 100 |
-
<button class="bg-white p-1 rounded-full text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-emerald-500 relative">
|
| 101 |
-
<i class="fas fa-bell h-6 w-6"></i>
|
| 102 |
-
<span class="absolute -top-1 -right-1 h-4 w-4 rounded-full bg-red-500 text-white text-xs flex items-center justify-center">3</span>
|
| 103 |
-
</button>
|
| 104 |
-
<div class="ml-3 relative">
|
| 105 |
-
<div>
|
| 106 |
-
<button type="button" class="flex text-sm rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-emerald-500" id="user-menu-button">
|
| 107 |
-
<img class="h-8 w-8 rounded-full" src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt="">
|
| 108 |
-
</button>
|
| 109 |
-
</div>
|
| 110 |
-
</div>
|
| 111 |
-
</div>
|
| 112 |
-
</div>
|
| 113 |
-
</div>
|
| 114 |
-
<div class="-mr-2 flex items-center sm:hidden">
|
| 115 |
-
<button type="button" class="inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-emerald-500" id="mobile-menu-button">
|
| 116 |
-
<i class="fas fa-bars"></i>
|
| 117 |
-
</button>
|
| 118 |
-
</div>
|
| 119 |
-
</div>
|
| 120 |
-
</div>
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
<
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
| 130 |
</div>
|
| 131 |
-
<div class="
|
| 132 |
-
<
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
</
|
| 136 |
-
<
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
<button class="ml-auto bg-white flex-shrink-0 p-1 rounded-full text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-emerald-500 relative">
|
| 141 |
-
<i class="fas fa-bell h-6 w-6"></i>
|
| 142 |
-
<span class="absolute -top-1 -right-1 h-4 w-4 rounded-full bg-red-500 text-white text-xs flex items-center justify-center">3</span>
|
| 143 |
-
</button>
|
| 144 |
-
</div>
|
| 145 |
-
</div>
|
| 146 |
-
</div>
|
| 147 |
-
</nav>
|
| 148 |
-
|
| 149 |
-
<!-- Main Content -->
|
| 150 |
-
<main class="py-6 px-4 sm:px-6 lg:px-8">
|
| 151 |
-
<!-- Header -->
|
| 152 |
-
<div class="mb-6 flex justify-between items-center">
|
| 153 |
-
<div>
|
| 154 |
-
<h1 class="text-2xl font-bold text-gray-900">Smart Farming 4.0 Dashboard</h1>
|
| 155 |
-
<p class="mt-1 text-sm text-gray-500">Eco-efficient IoT networks with AI predictions and blockchain security</p>
|
| 156 |
</div>
|
| 157 |
-
<div class="
|
| 158 |
-
<
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
<
|
| 163 |
-
|
|
|
|
| 164 |
</div>
|
| 165 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
<
|
| 172 |
-
<h2 class="text-lg font-medium text-gray-900">IoT Network Status</h2>
|
| 173 |
-
<span class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full flex items-center">
|
| 174 |
-
<span class="w-2 h-2 rounded-full bg-green-500 mr-1"></span> All Systems Operational
|
| 175 |
-
</span>
|
| 176 |
-
</div>
|
| 177 |
-
<div class="grid grid-cols-3 gap-4">
|
| 178 |
-
<div class="text-center">
|
| 179 |
-
<div class="mx-auto h-16 w-16 rounded-full bg-green-100 flex items-center justify-center mb-2">
|
| 180 |
-
<i class="fas fa-satellite-dish text-green-600 text-xl"></i>
|
| 181 |
-
</div>
|
| 182 |
-
<p class="text-sm text-gray-500">Nodes Online</p>
|
| 183 |
-
<p class="text-xl font-semibold text-gray-900">24/24</p>
|
| 184 |
-
</div>
|
| 185 |
-
<div class="text-center">
|
| 186 |
-
<div class="mx-auto h-16 w-16 rounded-full bg-blue-100 flex items-center justify-center mb-2">
|
| 187 |
-
<i class="fas fa-battery-three-quarters text-blue-600 text-xl"></i>
|
| 188 |
-
</div>
|
| 189 |
-
<p class="text-sm text-gray-500">Avg. Battery</p>
|
| 190 |
-
<p class="text-xl font-semibold text-gray-900">78%</p>
|
| 191 |
-
</div>
|
| 192 |
-
<div class="text-center">
|
| 193 |
-
<div class="mx-auto h-16 w-16 rounded-full bg-purple-100 flex items-center justify-center mb-2">
|
| 194 |
-
<i class="fas fa-signal text-purple-600 text-xl"></i>
|
| 195 |
-
</div>
|
| 196 |
-
<p class="text-sm text-gray-500">Signal Strength</p>
|
| 197 |
-
<p class="text-xl font-semibold text-gray-900">92%</p>
|
| 198 |
-
</div>
|
| 199 |
-
</div>
|
| 200 |
-
<div class="mt-4">
|
| 201 |
-
<div class="flex justify-between items-center mb-1">
|
| 202 |
-
<span class="text-sm font-medium text-gray-500">Data Transmission</span>
|
| 203 |
-
<span class="text-xs font-medium text-emerald-600">Eco Protocol v2.1</span>
|
| 204 |
-
</div>
|
| 205 |
-
<div class="w-full bg-gray-200 rounded-full h-2">
|
| 206 |
-
<div class="bg-emerald-500 h-2 rounded-full" style="width: 92%"></div>
|
| 207 |
-
</div>
|
| 208 |
-
<div class="flex justify-between text-xs text-gray-500 mt-1">
|
| 209 |
-
<span>0.5 KB/day</span>
|
| 210 |
-
<span>Optimal</span>
|
| 211 |
-
<span>5 KB/day</span>
|
| 212 |
-
</div>
|
| 213 |
-
</div>
|
| 214 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
<
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
<p class="text-sm text-gray-500">Last Hash</p>
|
| 237 |
-
<p class="text-xs font-mono text-gray-900 truncate">a3f8e2...</p>
|
| 238 |
-
</div>
|
| 239 |
-
<div class="text-center">
|
| 240 |
-
<div class="mx-auto h-16 w-16 rounded-full bg-red-100 flex items-center justify-center mb-2">
|
| 241 |
-
<i class="fas fa-shield-alt text-red-600 text-xl"></i>
|
| 242 |
-
</div>
|
| 243 |
-
<p class="text-sm text-gray-500">Integrity</p>
|
| 244 |
-
<p class="text-xl font-semibold text-gray-900">100%</p>
|
| 245 |
-
</div>
|
| 246 |
-
</div>
|
| 247 |
-
<div class="mt-4">
|
| 248 |
-
<div class="flex justify-between items-center mb-1">
|
| 249 |
-
<span class="text-sm font-medium text-gray-500">Data Encryption</span>
|
| 250 |
-
<span class="text-xs font-medium text-emerald-600">AES-256</span>
|
| 251 |
-
</div>
|
| 252 |
-
<div class="w-full bg-gray-200 rounded-full h-2">
|
| 253 |
-
<div class="bg-emerald-500 h-2 rounded-full" style="width: 100%"></div>
|
| 254 |
-
</div>
|
| 255 |
-
</div>
|
| 256 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
<
|
| 261 |
-
|
| 262 |
-
<span class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full flex items-center">
|
| 263 |
-
<i class="fas fa-brain mr-1"></i> Active
|
| 264 |
-
</span>
|
| 265 |
-
</div>
|
| 266 |
-
<div class="space-y-3">
|
| 267 |
-
<div class="flex items-center">
|
| 268 |
-
<div class="flex-shrink-0 h-10 w-10 rounded-full bg-green-100 flex items-center justify-center mr-3">
|
| 269 |
-
<i class="fas fa-tint text-green-600"></i>
|
| 270 |
-
</div>
|
| 271 |
-
<div class="flex-1 min-w-0">
|
| 272 |
-
<p class="text-sm font-medium text-gray-900 truncate">Next Irrigation</p>
|
| 273 |
-
<p class="text-sm text-gray-500">Field A in 8 hours</p>
|
| 274 |
-
</div>
|
| 275 |
-
<div class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full">92% accuracy</div>
|
| 276 |
-
</div>
|
| 277 |
-
<div class="flex items-center">
|
| 278 |
-
<div class="flex-shrink-0 h-10 w-10 rounded-full bg-yellow-100 flex items-center justify-center mr-3">
|
| 279 |
-
<i class="fas fa-bug text-yellow-600"></i>
|
| 280 |
-
</div>
|
| 281 |
-
<div class="flex-1 min-w-0">
|
| 282 |
-
<p class="text-sm font-medium text-gray-900 truncate">Pest Risk</p>
|
| 283 |
-
<p class="text-sm text-gray-500">Low (15%) in Field B</p>
|
| 284 |
-
</div>
|
| 285 |
-
<div class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full">87% accuracy</div>
|
| 286 |
-
</div>
|
| 287 |
-
<div class="flex items-center">
|
| 288 |
-
<div class="flex-shrink-0 h-10 w-10 rounded-full bg-purple-100 flex items-center justify-center mr-3">
|
| 289 |
-
<i class="fas fa-seedling text-purple-600"></i>
|
| 290 |
-
</div>
|
| 291 |
-
<div class="flex-1 min-w-0">
|
| 292 |
-
<p class="text-sm font-medium text-gray-900 truncate">Harvest Yield</p>
|
| 293 |
-
<p class="text-sm text-gray-500">+12% expected</p>
|
| 294 |
-
</div>
|
| 295 |
-
<div class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full">85% accuracy</div>
|
| 296 |
-
</div>
|
| 297 |
-
</div>
|
| 298 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
</div>
|
| 300 |
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
<
|
| 306 |
-
<h2 class="text-lg font-medium text-gray-900">IoT Network Map</h2>
|
| 307 |
-
<div class="flex space-x-2">
|
| 308 |
-
<span class="protocol-badge bg-green-100 text-green-800">LoRaWAN</span>
|
| 309 |
-
<span class="protocol-badge bg-blue-100 text-blue-800">Zigbee</span>
|
| 310 |
-
<span class="protocol-badge bg-purple-100 text-purple-800">NB-IoT</span>
|
| 311 |
-
</div>
|
| 312 |
-
</div>
|
| 313 |
-
<div class="relative h-64 bg-gray-100 rounded-lg overflow-hidden mb-4">
|
| 314 |
-
<!-- Simulated farm map with IoT nodes -->
|
| 315 |
-
<div class="absolute inset-0 bg-gradient-to-br from-green-50 to-blue-50">
|
| 316 |
-
<!-- Fields -->
|
| 317 |
-
<div class="absolute top-10 left-10 w-24 h-32 bg-green-100 border-2 border-green-300 rounded-lg"></div>
|
| 318 |
-
<div class="absolute top-16 left-40 w-32 h-24 bg-green-100 border-2 border-green-300 rounded-lg"></div>
|
| 319 |
-
<div class="absolute bottom-16 right-20 w-28 h-20 bg-green-100 border-2 border-green-300 rounded-lg"></div>
|
| 320 |
-
|
| 321 |
-
<!-- IoT Nodes -->
|
| 322 |
-
<div class="iot-node absolute top-20 left-20 h-6 w-6 rounded-full bg-emerald-500 flex items-center justify-center text-white">
|
| 323 |
-
<i class="fas fa-water text-xs"></i>
|
| 324 |
-
</div>
|
| 325 |
-
<div class="iot-node absolute top-24 left-60 h-6 w-6 rounded-full bg-blue-500 flex items-center justify-center text-white">
|
| 326 |
-
<i class="fas fa-temperature-high text-xs"></i>
|
| 327 |
-
</div>
|
| 328 |
-
<div class="iot-node absolute bottom-24 right-32 h-6 w-6 rounded-full bg-purple-500 flex items-center justify-center text-white">
|
| 329 |
-
<i class="fas fa-wind text-xs"></i>
|
| 330 |
-
</div>
|
| 331 |
-
<div class="iot-node absolute bottom-32 left-32 h-6 w-6 rounded-full bg-yellow-500 flex items-center justify-center text-white">
|
| 332 |
-
<i class="fas fa-lightbulb text-xs"></i>
|
| 333 |
-
</div>
|
| 334 |
-
|
| 335 |
-
<!-- Gateway -->
|
| 336 |
-
<div class="absolute top-8 right-8 h-10 w-10 rounded-full bg-indigo-600 flex items-center justify-center text-white">
|
| 337 |
-
<i class="fas fa-wifi"></i>
|
| 338 |
-
</div>
|
| 339 |
-
</div>
|
| 340 |
-
</div>
|
| 341 |
-
<div class="grid grid-cols-2 md:grid-cols-4 gap-2">
|
| 342 |
-
<div class="text-center">
|
| 343 |
-
<span class="inline-block h-3 w-3 rounded-full bg-emerald-500"></span>
|
| 344 |
-
<span class="ml-1 text-xs text-gray-600">Moisture</span>
|
| 345 |
-
</div>
|
| 346 |
-
<div class="text-center">
|
| 347 |
-
<span class="inline-block h-3 w-3 rounded-full bg-blue-500"></span>
|
| 348 |
-
<span class="ml-1 text-xs text-gray-600">Temperature</span>
|
| 349 |
-
</div>
|
| 350 |
-
<div class="text-center">
|
| 351 |
-
<span class="inline-block h-3 w-3 rounded-full bg-purple-500"></span>
|
| 352 |
-
<span class="ml-1 text-xs text-gray-600">Humidity</span>
|
| 353 |
-
</div>
|
| 354 |
-
<div class="text-center">
|
| 355 |
-
<span class="inline-block h-3 w-3 rounded-full bg-yellow-500"></span>
|
| 356 |
-
<span class="ml-1 text-xs text-gray-600">Light</span>
|
| 357 |
-
</div>
|
| 358 |
-
</div>
|
| 359 |
-
<div class="mt-4">
|
| 360 |
-
<div class="flex justify-between items-center">
|
| 361 |
-
<span class="text-sm font-medium text-gray-600">Network Protocols Efficiency</span>
|
| 362 |
-
<span class="text-xs text-emerald-600">Eco Mode Active</span>
|
| 363 |
-
</div>
|
| 364 |
-
<div class="mt-2 space-y-2">
|
| 365 |
-
<div>
|
| 366 |
-
<div class="flex justify-between text-xs text-gray-500 mb-1">
|
| 367 |
-
<span>LoRaWAN</span>
|
| 368 |
-
<span>0.8 KB/day</span>
|
| 369 |
-
</div>
|
| 370 |
-
<div class="w-full bg-gray-200 rounded-full h-2">
|
| 371 |
-
<div class="bg-green-500 h-2 rounded-full" style="width: 90%"></div>
|
| 372 |
-
</div>
|
| 373 |
-
</div>
|
| 374 |
-
<div>
|
| 375 |
-
<div class="flex justify-between text-xs text-gray-500 mb-1">
|
| 376 |
-
<span>Zigbee</span>
|
| 377 |
-
<span>1.2 KB/day</span>
|
| 378 |
-
</div>
|
| 379 |
-
<div class="w-full bg-gray-200 rounded-full h-2">
|
| 380 |
-
<div class="bg-blue-500 h-2 rounded-full" style="width: 85%"></div>
|
| 381 |
-
</div>
|
| 382 |
-
</div>
|
| 383 |
-
<div>
|
| 384 |
-
<div class="flex justify-between text-xs text-gray-500 mb-1">
|
| 385 |
-
<span>NB-IoT</span>
|
| 386 |
-
<span>0.5 KB/day</span>
|
| 387 |
-
</div>
|
| 388 |
-
<div class="w-full bg-gray-200 rounded-full h-2">
|
| 389 |
-
<div class="bg-purple-500 h-2 rounded-full" style="width: 95%"></div>
|
| 390 |
-
</div>
|
| 391 |
-
</div>
|
| 392 |
-
</div>
|
| 393 |
-
</div>
|
| 394 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
<
|
| 399 |
-
<h2 class="text-lg font-medium text-gray-900">AI Prediction Analysis</h2>
|
| 400 |
-
<div class="flex items-center">
|
| 401 |
-
<span class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full mr-2">Model v3.2</span>
|
| 402 |
-
<button class="text-emerald-600 hover:text-emerald-800">
|
| 403 |
-
<i class="fas fa-cog"></i>
|
| 404 |
-
</button>
|
| 405 |
-
</div>
|
| 406 |
-
</div>
|
| 407 |
-
<div class="mb-4">
|
| 408 |
-
<div id="aiChart" class="h-48"></div>
|
| 409 |
-
</div>
|
| 410 |
-
<div class="space-y-3">
|
| 411 |
-
<div class="flex items-start">
|
| 412 |
-
<div class="flex-shrink-0 h-10 w-10 rounded-full bg-red-100 flex items-center justify-center mr-3 mt-1">
|
| 413 |
-
<i class="fas fa-exclamation-triangle text-red-600"></i>
|
| 414 |
-
</div>
|
| 415 |
-
<div>
|
| 416 |
-
<p class="text-sm font-medium text-gray-900">Disease Detection</p>
|
| 417 |
-
<p class="text-sm text-gray-500">Early blight detected in 3 tomato plants with 89% confidence. Recommended treatment: Copper fungicide spray.</p>
|
| 418 |
-
</div>
|
| 419 |
-
</div>
|
| 420 |
-
<div class="flex items-start">
|
| 421 |
-
<div class="flex-shrink-0 h-10 w-10 rounded-full bg-blue-100 flex items-center justify-center mr-3 mt-1">
|
| 422 |
-
<i class="fas fa-tint text-blue-600"></i>
|
| 423 |
-
</div>
|
| 424 |
-
<div>
|
| 425 |
-
<p class="text-sm font-medium text-gray-900">Water Optimization</p>
|
| 426 |
-
<p class="text-sm text-gray-500">AI recommends reducing irrigation in Field B by 15% based on soil moisture forecasts.</p>
|
| 427 |
-
</div>
|
| 428 |
-
</div>
|
| 429 |
-
<div class="flex items-start">
|
| 430 |
-
<div class="flex-shrink-0 h-10 w-10 rounded-full bg-yellow-100 flex items-center justify-center mr-3 mt-1">
|
| 431 |
-
<i class="fas fa-calendar-alt text-yellow-600"></i>
|
| 432 |
-
</div>
|
| 433 |
-
<div>
|
| 434 |
-
<p class="text-sm font-medium text-gray-900">Harvest Timing</p>
|
| 435 |
-
<p class="text-sm text-gray-500">Optimal harvest window predicted between July 15-18 for maximum yield and quality.</p>
|
| 436 |
-
</div>
|
| 437 |
-
</div>
|
| 438 |
-
</div>
|
| 439 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
</div>
|
| 441 |
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
<div class="
|
| 445 |
-
<
|
| 446 |
-
|
| 447 |
-
<button class="px-3 py-1 text-xs bg-emerald-100 text-emerald-700 rounded-full flex items-center">
|
| 448 |
-
<i class="fas fa-plus mr-1"></i> New Block
|
| 449 |
-
</button>
|
| 450 |
-
</div>
|
| 451 |
-
</div>
|
| 452 |
-
<div class="divide-y divide-gray-200">
|
| 453 |
-
<div class="p-4 hover:bg-gray-50 blockchain-block">
|
| 454 |
-
<div class="flex items-center">
|
| 455 |
-
<div class="flex-shrink-0 h-10 w-10 rounded-full bg-indigo-100 flex items-center justify-center mr-3">
|
| 456 |
-
<i class="fas fa-cube text-indigo-600"></i>
|
| 457 |
-
</div>
|
| 458 |
-
<div class="flex-1 min-w-0">
|
| 459 |
-
<p class="text-sm font-medium text-gray-900 truncate">Block #4892</p>
|
| 460 |
-
<div class="flex items-center text-xs text-gray-500">
|
| 461 |
-
<span class="truncate mr-2">Hash: a3f8e2d4b5c71f9e8a0b6d5c4f3e2a1b</span>
|
| 462 |
-
<span class="flex-shrink-0">2 mins ago</span>
|
| 463 |
-
</div>
|
| 464 |
-
</div>
|
| 465 |
-
<div class="ml-4 flex-shrink-0">
|
| 466 |
-
<div class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full">Validated</div>
|
| 467 |
-
</div>
|
| 468 |
-
</div>
|
| 469 |
-
<div class="mt-2 ml-13 grid grid-cols-3 gap-2 text-xs">
|
| 470 |
-
<div class="bg-gray-100 p-1 rounded">
|
| 471 |
-
<p class="text-gray-500">Data Type</p>
|
| 472 |
-
<p class="font-medium">Soil Moisture</p>
|
| 473 |
-
</div>
|
| 474 |
-
<div class="bg-gray-100 p-1 rounded">
|
| 475 |
-
<p class="text-gray-500">Field</p>
|
| 476 |
-
<p class="font-medium">A</p>
|
| 477 |
-
</div>
|
| 478 |
-
<div class="bg-gray-100 p-1 rounded">
|
| 479 |
-
<p class="text-gray-500">Value</p>
|
| 480 |
-
<p class="font-medium">68%</p>
|
| 481 |
-
</div>
|
| 482 |
-
</div>
|
| 483 |
-
</div>
|
| 484 |
-
<div class="p-4 hover:bg-gray-50 blockchain-block">
|
| 485 |
-
<div class="flex items-center">
|
| 486 |
-
<div class="flex-shrink-0 h-10 w-10 rounded-full bg-indigo-100 flex items-center justify-center mr-3">
|
| 487 |
-
<i class="fas fa-cube text-indigo-600"></i>
|
| 488 |
-
</div>
|
| 489 |
-
<div class="flex-1 min-w-0">
|
| 490 |
-
<p class="text-sm font-medium text-gray-900 truncate">Block #4891</p>
|
| 491 |
-
<div class="flex items-center text-xs text-gray-500">
|
| 492 |
-
<span class="truncate mr-2">Hash: b5c71f9e8a0b6d5c4f3e2a1ba3f8e2d</span>
|
| 493 |
-
<span class="flex-shrink-0">15 mins ago</span>
|
| 494 |
-
</div>
|
| 495 |
-
</div>
|
| 496 |
-
<div class="ml-4 flex-shrink-0">
|
| 497 |
-
<div class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full">Validated</div>
|
| 498 |
-
</div>
|
| 499 |
-
</div>
|
| 500 |
-
<div class="mt-2 ml-13 grid grid-cols-3 gap-2 text-xs">
|
| 501 |
-
<div class="bg-gray-100 p-1 rounded">
|
| 502 |
-
<p class="text-gray-500">Data Type</p>
|
| 503 |
-
<p class="font-medium">Temperature</p>
|
| 504 |
-
</div>
|
| 505 |
-
<div class="bg-gray-100 p-1 rounded">
|
| 506 |
-
<p class="text-gray-500">Field</p>
|
| 507 |
-
<p class="font-medium">B</p>
|
| 508 |
-
</div>
|
| 509 |
-
<div class="bg-gray-100 p-1 rounded">
|
| 510 |
-
<p class="text-gray-500">Value</p>
|
| 511 |
-
<p class="font-medium">24.5°C</p>
|
| 512 |
-
</div>
|
| 513 |
-
</div>
|
| 514 |
-
</div>
|
| 515 |
-
<div class="p-4 hover:bg-gray-50 blockchain-block">
|
| 516 |
-
<div class="flex items-center">
|
| 517 |
-
<div class="flex-shrink-0 h-10 w-10 rounded-full bg-indigo-100 flex items-center justify-center mr-3">
|
| 518 |
-
<i class="fas fa-cube text-indigo-600"></i>
|
| 519 |
-
</div>
|
| 520 |
-
<div class="flex-1 min-w-0">
|
| 521 |
-
<p class="text-sm font-medium text-gray-900 truncate">Block #4890</p>
|
| 522 |
-
<div class="flex items-center text-xs text-gray-500">
|
| 523 |
-
<span class="truncate mr-2">Hash: d4b5c71f9e8a0b6d5c4f3e2a1ba3f8e</span>
|
| 524 |
-
<span class="flex-shrink-0">32 mins ago</span>
|
| 525 |
-
</div>
|
| 526 |
-
</div>
|
| 527 |
-
<div class="ml-4 flex-shrink-0">
|
| 528 |
-
<div class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full">Validated</div>
|
| 529 |
-
</div>
|
| 530 |
-
</div>
|
| 531 |
-
<div class="mt-2 ml-13 grid grid-cols-3 gap-2 text-xs">
|
| 532 |
-
<div class="bg-gray-100 p-1 rounded">
|
| 533 |
-
<p class="text-gray-500">Data Type</p>
|
| 534 |
-
<p class="font-medium">Pest Alert</p>
|
| 535 |
-
</div>
|
| 536 |
-
<div class="bg-gray-100 p-1 rounded">
|
| 537 |
-
<p class="text-gray-500">Field</p>
|
| 538 |
-
<p class="font-medium">C</p>
|
| 539 |
-
</div>
|
| 540 |
-
<div class="bg-gray-100 p-1 rounded">
|
| 541 |
-
<p class="text-gray-500">Value</p>
|
| 542 |
-
<p class="font-medium">Corn Borer</p>
|
| 543 |
-
</div>
|
| 544 |
-
</div>
|
| 545 |
-
</div>
|
| 546 |
</div>
|
| 547 |
-
<
|
| 548 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 549 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
</div>
|
| 551 |
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
<div class="
|
| 555 |
-
<
|
| 556 |
-
<
|
| 557 |
-
<span class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full mr-2">Live</span>
|
| 558 |
-
<span class="text-xs text-gray-500">Updated: <span id="updateTime">Just now</span></span>
|
| 559 |
-
</div>
|
| 560 |
-
</div>
|
| 561 |
-
<div class="sensor-grid">
|
| 562 |
-
<div class="bg-gray-50 p-3 rounded-lg">
|
| 563 |
-
<div class="flex justify-between items-start">
|
| 564 |
-
<div>
|
| 565 |
-
<p class="text-xs text-gray-500">Soil Moisture</p>
|
| 566 |
-
<p class="text-xl font-semibold"><span id="soilMoisture">72</span>%</p>
|
| 567 |
-
</div>
|
| 568 |
-
<div class="h-8 w-8 rounded-full bg-green-100 flex items-center justify-center">
|
| 569 |
-
<i class="fas fa-tint text-green-600 text-sm"></i>
|
| 570 |
-
</div>
|
| 571 |
-
</div>
|
| 572 |
-
<div class="mt-2">
|
| 573 |
-
<div class="w-full bg-gray-200 rounded-full h-1">
|
| 574 |
-
<div class="bg-green-500 h-1 rounded-full" style="width: 72%"></div>
|
| 575 |
-
</div>
|
| 576 |
-
</div>
|
| 577 |
-
</div>
|
| 578 |
-
<div class="bg-gray-50 p-3 rounded-lg">
|
| 579 |
-
<div class="flex justify-between items-start">
|
| 580 |
-
<div>
|
| 581 |
-
<p class="text-xs text-gray-500">Temperature</p>
|
| 582 |
-
<p class="text-xl font-semibold"><span id="temperature">24.5</span>°C</p>
|
| 583 |
-
</div>
|
| 584 |
-
<div class="h-8 w-8 rounded-full bg-blue-100 flex items-center justify-center">
|
| 585 |
-
<i class="fas fa-temperature-high text-blue-600 text-sm"></i>
|
| 586 |
-
</div>
|
| 587 |
-
</div>
|
| 588 |
-
<div class="mt-2">
|
| 589 |
-
<div class="w-full bg-gray-200 rounded-full h-1">
|
| 590 |
-
<div class="bg-blue-500 h-1 rounded-full" style="width: 65%"></div>
|
| 591 |
-
</div>
|
| 592 |
-
</div>
|
| 593 |
-
</div>
|
| 594 |
-
<div class="bg-gray-50 p-3 rounded-lg">
|
| 595 |
-
<div class="flex justify-between items-start">
|
| 596 |
-
<div>
|
| 597 |
-
<p class="text-xs text-gray-500">Humidity</p>
|
| 598 |
-
<p class="text-xl font-semibold"><span id="humidity">65</span>%</p>
|
| 599 |
-
</div>
|
| 600 |
-
<div class="h-8 w-8 rounded-full bg-purple-100 flex items-center justify-center">
|
| 601 |
-
<i class="fas fa-wind text-purple-600 text-sm"></i>
|
| 602 |
-
</div>
|
| 603 |
-
</div>
|
| 604 |
-
<div class="mt-2">
|
| 605 |
-
<div class="w-full bg-gray-200 rounded-full h-1">
|
| 606 |
-
<div class="bg-purple-500 h-1 rounded-full" style="width: 65%"></div>
|
| 607 |
-
</div>
|
| 608 |
-
</div>
|
| 609 |
-
</div>
|
| 610 |
-
<div class="bg-gray-50 p-3 rounded-lg">
|
| 611 |
-
<div class="flex justify-between items-start">
|
| 612 |
-
<div>
|
| 613 |
-
<p class="text-xs text-gray-500">Light Intensity</p>
|
| 614 |
-
<p class="text-xl font-semibold"><span id="lightIntensity">850</span> lux</p>
|
| 615 |
-
</div>
|
| 616 |
-
<div class="h-8 w-8 rounded-full bg-yellow-100 flex items-center justify-center">
|
| 617 |
-
<i class="fas fa-sun text-yellow-600 text-sm"></i>
|
| 618 |
-
</div>
|
| 619 |
-
</div>
|
| 620 |
-
<div class="mt-2">
|
| 621 |
-
<div class="w-full bg-gray-200 rounded-full h-1">
|
| 622 |
-
<div class="bg-yellow-500 h-1 rounded-full" style="width: 75%"></div>
|
| 623 |
-
</div>
|
| 624 |
-
</div>
|
| 625 |
-
</div>
|
| 626 |
-
<div class="bg-gray-50 p-3 rounded-lg">
|
| 627 |
-
<div class="flex justify-between items-start">
|
| 628 |
-
<div>
|
| 629 |
-
<p class="text-xs text-gray-500">pH Level</p>
|
| 630 |
-
<p class="text-xl font-semibold"><span id="phLevel">6.8</span></p>
|
| 631 |
-
</div>
|
| 632 |
-
<div class="h-8 w-8 rounded-full bg-pink-100 flex items-center justify-center">
|
| 633 |
-
<i class="fas fa-flask text-pink-600 text-sm"></i>
|
| 634 |
-
</div>
|
| 635 |
-
</div>
|
| 636 |
-
<div class="mt-2">
|
| 637 |
-
<div class="w-full bg-gray-200 rounded-full h-1">
|
| 638 |
-
<div class="bg-pink-500 h-1 rounded-full" style="width: 80%"></div>
|
| 639 |
-
</div>
|
| 640 |
-
</div>
|
| 641 |
-
</div>
|
| 642 |
-
<div class="bg-gray-50 p-3 rounded-lg">
|
| 643 |
-
<div class="flex justify-between items-start">
|
| 644 |
-
<div>
|
| 645 |
-
<p class="text-xs text-gray-500">CO2 Level</p>
|
| 646 |
-
<p class="text-xl font-semibold"><span id="co2Level">420</span> ppm</p>
|
| 647 |
-
</div>
|
| 648 |
-
<div class="h-8 w-8 rounded-full bg-indigo-100 flex items-center justify-center">
|
| 649 |
-
<i class="fas fa-cloud text-indigo-600 text-sm"></i>
|
| 650 |
-
</div>
|
| 651 |
-
</div>
|
| 652 |
-
<div class="mt-2">
|
| 653 |
-
<div class="w-full bg-gray-200 rounded-full h-1">
|
| 654 |
-
<div class="bg-indigo-500 h-1 rounded-full" style="width: 55%"></div>
|
| 655 |
-
</div>
|
| 656 |
-
</div>
|
| 657 |
-
</div>
|
| 658 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 659 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 660 |
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
<
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 670 |
</div>
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
</div>
|
| 737 |
-
<div class="flex justify-between">
|
| 738 |
-
<span>ML Models</span>
|
| 739 |
-
<span class="font-medium">3 active</span>
|
| 740 |
-
</div>
|
| 741 |
-
<div class="flex justify-between">
|
| 742 |
-
<span>Storage</span>
|
| 743 |
-
<span class="font-medium">1.5 TB</span>
|
| 744 |
-
</div>
|
| 745 |
-
</div>
|
| 746 |
-
</div>
|
| 747 |
</div>
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 753 |
</div>
|
| 754 |
</div>
|
| 755 |
-
</
|
| 756 |
-
</div>
|
| 757 |
-
|
| 758 |
-
<script>
|
| 759 |
-
// Mobile menu toggle
|
| 760 |
-
const mobileMenuButton = document.getElementById('mobile-menu-button');
|
| 761 |
-
const mobileMenu = document.getElementById('mobile-menu');
|
| 762 |
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 766 |
|
| 767 |
-
//
|
| 768 |
-
const
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
type: 'line',
|
| 779 |
-
toolbar: {
|
| 780 |
-
show: false
|
| 781 |
-
}
|
| 782 |
-
},
|
| 783 |
-
colors: ['#10B981', '#3B82F6'],
|
| 784 |
-
dataLabels: {
|
| 785 |
-
enabled: false
|
| 786 |
-
},
|
| 787 |
-
stroke: {
|
| 788 |
-
curve: 'smooth',
|
| 789 |
-
width: [3, 3]
|
| 790 |
-
},
|
| 791 |
-
xaxis: {
|
| 792 |
-
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep'],
|
| 793 |
-
},
|
| 794 |
-
tooltip: {
|
| 795 |
-
y: {
|
| 796 |
-
formatter: function (val) {
|
| 797 |
-
return val + " liters"
|
| 798 |
-
}
|
| 799 |
-
}
|
| 800 |
-
},
|
| 801 |
-
legend: {
|
| 802 |
-
position: 'top'
|
| 803 |
-
}
|
| 804 |
-
};
|
| 805 |
|
| 806 |
-
|
| 807 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 808 |
|
| 809 |
-
//
|
| 810 |
-
|
| 811 |
-
const
|
| 812 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 813 |
|
| 814 |
-
//
|
| 815 |
-
const
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
phLevel: { min: 6.5, max: 7.0, unit: '', decimals: 1 },
|
| 821 |
-
co2Level: { min: 400, max: 450, unit: ' ppm' }
|
| 822 |
};
|
| 823 |
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
}
|
| 835 |
|
| 836 |
-
|
| 837 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 838 |
|
| 839 |
-
//
|
| 840 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 841 |
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 865 |
|
| 866 |
-
//
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
'CO2 Level': { unit: ' ppm', min: 400, max: 450 }
|
| 876 |
-
};
|
| 877 |
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 881 |
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 885 |
|
| 886 |
-
|
| 887 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 888 |
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 894 |
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 898 |
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Abder004/smartfarming" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 899 |
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
<head>
|
| 4 |
+
<title>AgriChain Backend Documentation</title>
|
|
|
|
|
|
|
| 5 |
<script src="https://cdn.tailwindcss.com"></script>
|
|
|
|
|
|
|
|
|
|
| 6 |
<style>
|
| 7 |
+
pre {
|
| 8 |
+
background-color: #f8f8f8;
|
| 9 |
+
border-radius: 5px;
|
| 10 |
+
padding: 15px;
|
| 11 |
+
overflow-x: auto;
|
|
|
|
|
|
|
| 12 |
}
|
| 13 |
+
.endpoint {
|
| 14 |
+
border-left: 4px solid #10b981;
|
| 15 |
+
padding-left: 1rem;
|
| 16 |
+
margin-bottom: 2rem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
}
|
| 18 |
</style>
|
| 19 |
</head>
|
| 20 |
+
<body class="bg-gray-50 p-8">
|
| 21 |
+
<div class="max-w-6xl mx-auto bg-white rounded-lg shadow-lg p-8">
|
| 22 |
+
<div class="flex items-center mb-8">
|
| 23 |
+
<i class="fas fa-leaf text-emerald-500 text-3xl mr-3"></i>
|
| 24 |
+
<h1 class="text-3xl font-bold text-gray-800">AgriChain Backend API</h1>
|
| 25 |
+
</div>
|
| 26 |
+
|
| 27 |
+
<div class="mb-8">
|
| 28 |
+
<h2 class="text-xl font-semibold text-gray-800 mb-4">System Overview</h2>
|
| 29 |
+
<p class="text-gray-600 mb-4">
|
| 30 |
+
The AgriChain backend provides RESTful APIs for the smart farming dashboard, handling IoT device data,
|
| 31 |
+
blockchain transactions, AI predictions, and user management.
|
| 32 |
+
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
|
| 35 |
+
<div class="bg-emerald-50 p-4 rounded-lg">
|
| 36 |
+
<h3 class="font-medium text-emerald-800 mb-2">Tech Stack</h3>
|
| 37 |
+
<ul class="text-sm text-gray-700 space-y-1">
|
| 38 |
+
<li>Node.js v18+</li>
|
| 39 |
+
<li>Express.js</li>
|
| 40 |
+
<li>MongoDB (with Mongoose)</li>
|
| 41 |
+
<li>JWT Authentication</li>
|
| 42 |
+
<li>Web3.js for blockchain</li>
|
| 43 |
+
<li>TensorFlow.js for AI</li>
|
| 44 |
+
</ul>
|
| 45 |
</div>
|
| 46 |
+
<div class="bg-blue-50 p-4 rounded-lg">
|
| 47 |
+
<h3 class="font-medium text-blue-800 mb-2">Key Features</h3>
|
| 48 |
+
<ul class="text-sm text-gray-700 space-y-1">
|
| 49 |
+
<li>Real-time IoT data processing</li>
|
| 50 |
+
<li>Blockchain data integrity</li>
|
| 51 |
+
<li>AI prediction models</li>
|
| 52 |
+
<li>User authentication</li>
|
| 53 |
+
<li>Cloud integration</li>
|
| 54 |
+
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
</div>
|
| 56 |
+
<div class="bg-purple-50 p-4 rounded-lg">
|
| 57 |
+
<h3 class="font-medium text-purple-800 mb-2">Deployment</h3>
|
| 58 |
+
<ul class="text-sm text-gray-700 space-y-1">
|
| 59 |
+
<li>Docker containerization</li>
|
| 60 |
+
<li>Kubernetes for orchestration</li>
|
| 61 |
+
<li>AWS ECS/EKS</li>
|
| 62 |
+
<li>CI/CD with GitHub Actions</li>
|
| 63 |
+
</ul>
|
| 64 |
</div>
|
| 65 |
</div>
|
| 66 |
+
</div>
|
| 67 |
+
|
| 68 |
+
<div class="mb-8">
|
| 69 |
+
<h2 class="text-xl font-semibold text-gray-800 mb-4">Installation</h2>
|
| 70 |
+
<pre><code class="language-bash">
|
| 71 |
+
# Clone the repository
|
| 72 |
+
git clone https://github.com/agrichain/backend.git
|
| 73 |
+
cd backend
|
| 74 |
+
|
| 75 |
+
# Install dependencies
|
| 76 |
+
npm install
|
| 77 |
+
|
| 78 |
+
# Set up environment variables
|
| 79 |
+
cp .env.example .env
|
| 80 |
+
# Edit .env with your configuration
|
| 81 |
+
|
| 82 |
+
# Start the development server
|
| 83 |
+
npm run dev
|
| 84 |
+
|
| 85 |
+
# For production
|
| 86 |
+
npm run build
|
| 87 |
+
npm start
|
| 88 |
+
</code></pre>
|
| 89 |
+
</div>
|
| 90 |
+
|
| 91 |
+
<div class="mb-8">
|
| 92 |
+
<h2 class="text-xl font-semibold text-gray-800 mb-4">API Endpoints</h2>
|
| 93 |
|
| 94 |
+
<div class="endpoint">
|
| 95 |
+
<h3 class="text-lg font-medium text-gray-800 mb-2">Authentication</h3>
|
| 96 |
+
<div class="mb-4">
|
| 97 |
+
<span class="bg-green-100 text-green-800 text-xs font-medium px-2.5 py-0.5 rounded">POST</span>
|
| 98 |
+
<span class="ml-2 font-mono">/api/auth/register</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
</div>
|
| 100 |
+
<pre><code class="language-javascript">
|
| 101 |
+
// Request Body
|
| 102 |
+
{
|
| 103 |
+
"name": "John Farmer",
|
| 104 |
+
"email": "john@example.com",
|
| 105 |
+
"password": "securepassword123",
|
| 106 |
+
"farmName": "Green Valley Farms"
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
// Response
|
| 110 |
+
{
|
| 111 |
+
"success": true,
|
| 112 |
+
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
| 113 |
+
"user": {
|
| 114 |
+
"id": "507f1f77bcf86cd799439011",
|
| 115 |
+
"name": "John Farmer",
|
| 116 |
+
"email": "john@example.com",
|
| 117 |
+
"farmName": "Green Valley Farms"
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
</code></pre>
|
| 121 |
|
| 122 |
+
<div class="mb-4 mt-6">
|
| 123 |
+
<span class="bg-green-100 text-green-800 text-xs font-medium px-2.5 py-0.5 rounded">POST</span>
|
| 124 |
+
<span class="ml-2 font-mono">/api/auth/login</span>
|
| 125 |
+
</div>
|
| 126 |
+
<pre><code class="language-javascript">
|
| 127 |
+
// Request Body
|
| 128 |
+
{
|
| 129 |
+
"email": "john@example.com",
|
| 130 |
+
"password": "securepassword123"
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
// Response (same structure as register)
|
| 134 |
+
</code></pre>
|
| 135 |
+
</div>
|
| 136 |
+
|
| 137 |
+
<div class="endpoint">
|
| 138 |
+
<h3 class="text-lg font-medium text-gray-800 mb-2">IoT Device Management</h3>
|
| 139 |
+
<div class="mb-4">
|
| 140 |
+
<span class="bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded">GET</span>
|
| 141 |
+
<span class="ml-2 font-mono">/api/iot/devices</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
</div>
|
| 143 |
+
<pre><code class="language-javascript">
|
| 144 |
+
// Response
|
| 145 |
+
{
|
| 146 |
+
"success": true,
|
| 147 |
+
"devices": [
|
| 148 |
+
{
|
| 149 |
+
"id": "60d5ec9cfb9d8b3a48fe9a12",
|
| 150 |
+
"name": "Soil Moisture Sensor - Field A",
|
| 151 |
+
"type": "moisture",
|
| 152 |
+
"status": "online",
|
| 153 |
+
"batteryLevel": 78,
|
| 154 |
+
"signalStrength": 92,
|
| 155 |
+
"lastReading": {
|
| 156 |
+
"value": 72,
|
| 157 |
+
"timestamp": "2023-06-15T08:30:45.000Z"
|
| 158 |
+
},
|
| 159 |
+
"location": {
|
| 160 |
+
"field": "A",
|
| 161 |
+
"coordinates": [34.0522, -118.2437]
|
| 162 |
+
}
|
| 163 |
+
},
|
| 164 |
+
// ... more devices
|
| 165 |
+
]
|
| 166 |
+
}
|
| 167 |
+
</code></pre>
|
| 168 |
|
| 169 |
+
<div class="mb-4 mt-6">
|
| 170 |
+
<span class="bg-yellow-100 text-yellow-800 text-xs font-medium px-2.5 py-0.5 rounded">POST</span>
|
| 171 |
+
<span class="ml-2 font-mono">/api/iot/data</span>
|
| 172 |
+
<span class="text-sm text-gray-500 ml-2">(for IoT devices to send data)</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
</div>
|
| 174 |
+
<pre><code class="language-javascript">
|
| 175 |
+
// Request Body
|
| 176 |
+
{
|
| 177 |
+
"deviceId": "60d5ec9cfb9d8b3a48fe9a12",
|
| 178 |
+
"secretKey": "device-secret-key",
|
| 179 |
+
"readings": [
|
| 180 |
+
{
|
| 181 |
+
"type": "moisture",
|
| 182 |
+
"value": 72,
|
| 183 |
+
"timestamp": "2023-06-15T08:30:45.000Z"
|
| 184 |
+
}
|
| 185 |
+
]
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
// Response
|
| 189 |
+
{
|
| 190 |
+
"success": true,
|
| 191 |
+
"message": "Data received and stored",
|
| 192 |
+
"blockchainHash": "a3f8e2d4b5c71f9e8a0b6d5c4f3e2a1b"
|
| 193 |
+
}
|
| 194 |
+
</code></pre>
|
| 195 |
</div>
|
| 196 |
|
| 197 |
+
<div class="endpoint">
|
| 198 |
+
<h3 class="text-lg font-medium text-gray-800 mb-2">Blockchain</h3>
|
| 199 |
+
<div class="mb-4">
|
| 200 |
+
<span class="bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded">GET</span>
|
| 201 |
+
<span class="ml-2 font-mono">/api/blockchain/blocks</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
</div>
|
| 203 |
+
<pre><code class="language-javascript">
|
| 204 |
+
// Response
|
| 205 |
+
{
|
| 206 |
+
"success": true,
|
| 207 |
+
"blocks": [
|
| 208 |
+
{
|
| 209 |
+
"index": 4892,
|
| 210 |
+
"timestamp": "2023-06-15T08:30:45.000Z",
|
| 211 |
+
"data": {
|
| 212 |
+
"deviceId": "60d5ec9cfb9d8b3a48fe9a12",
|
| 213 |
+
"readingType": "moisture",
|
| 214 |
+
"value": 72,
|
| 215 |
+
"field": "A"
|
| 216 |
+
},
|
| 217 |
+
"previousHash": "b5c71f9e8a0b6d5c4f3e2a1ba3f8e2d",
|
| 218 |
+
"hash": "a3f8e2d4b5c71f9e8a0b6d5c4f3e2a1b"
|
| 219 |
+
},
|
| 220 |
+
// ... more blocks
|
| 221 |
+
]
|
| 222 |
+
}
|
| 223 |
+
</code></pre>
|
| 224 |
|
| 225 |
+
<div class="mb-4 mt-6">
|
| 226 |
+
<span class="bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded">GET</span>
|
| 227 |
+
<span class="ml-2 font-mono">/api/blockchain/validate</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
</div>
|
| 229 |
+
<pre><code class="language-javascript">
|
| 230 |
+
// Response
|
| 231 |
+
{
|
| 232 |
+
"success": true,
|
| 233 |
+
"valid": true,
|
| 234 |
+
"invalidBlocks": [],
|
| 235 |
+
"message": "Blockchain integrity verified"
|
| 236 |
+
}
|
| 237 |
+
</code></pre>
|
| 238 |
</div>
|
| 239 |
|
| 240 |
+
<div class="endpoint">
|
| 241 |
+
<h3 class="text-lg font-medium text-gray-800 mb-2">AI Predictions</h3>
|
| 242 |
+
<div class="mb-4">
|
| 243 |
+
<span class="bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded">GET</span>
|
| 244 |
+
<span class="ml-2 font-mono">/api/ai/predictions</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
</div>
|
| 246 |
+
<pre><code class="language-javascript">
|
| 247 |
+
// Response
|
| 248 |
+
{
|
| 249 |
+
"success": true,
|
| 250 |
+
"predictions": [
|
| 251 |
+
{
|
| 252 |
+
"type": "irrigation",
|
| 253 |
+
"field": "A",
|
| 254 |
+
"prediction": "Next irrigation in 8 hours",
|
| 255 |
+
"confidence": 0.92,
|
| 256 |
+
"recommendation": "Delay watering until evening to reduce evaporation"
|
| 257 |
+
},
|
| 258 |
+
{
|
| 259 |
+
"type": "pest",
|
| 260 |
+
"field": "B",
|
| 261 |
+
"prediction": "Low pest risk (15%)",
|
| 262 |
+
"confidence": 0.87,
|
| 263 |
+
"recommendation": "Monitor for corn borer, no treatment needed yet"
|
| 264 |
+
},
|
| 265 |
+
{
|
| 266 |
+
"type": "harvest",
|
| 267 |
+
"field": "C",
|
| 268 |
+
"prediction": "Optimal harvest window: July 15-18",
|
| 269 |
+
"confidence": 0.85,
|
| 270 |
+
"recommendation": "Prepare workforce and storage for peak yield"
|
| 271 |
+
}
|
| 272 |
+
]
|
| 273 |
+
}
|
| 274 |
+
</code></pre>
|
| 275 |
+
|
| 276 |
+
<div class="mb-4 mt-6">
|
| 277 |
+
<span class="bg-yellow-100 text-yellow-800 text-xs font-medium px-2.5 py-0.5 rounded">POST</span>
|
| 278 |
+
<span class="ml-2 font-mono">/api/ai/train</span>
|
| 279 |
+
<span class="text-sm text-gray-500 ml-2">(Admin only - retrain models)</span>
|
| 280 |
</div>
|
| 281 |
+
<pre><code class="language-javascript">
|
| 282 |
+
// Response
|
| 283 |
+
{
|
| 284 |
+
"success": true,
|
| 285 |
+
"message": "AI models retrained successfully",
|
| 286 |
+
"newAccuracy": {
|
| 287 |
+
"irrigation": 0.93,
|
| 288 |
+
"pest": 0.88,
|
| 289 |
+
"harvest": 0.86
|
| 290 |
+
}
|
| 291 |
+
}
|
| 292 |
+
</code></pre>
|
| 293 |
</div>
|
| 294 |
|
| 295 |
+
<div class="endpoint">
|
| 296 |
+
<h3 class="text-lg font-medium text-gray-800 mb-2">Cloud Integration</h3>
|
| 297 |
+
<div class="mb-4">
|
| 298 |
+
<span class="bg-blue-100 text-blue-800 text-xs font-medium px-2.5 py-0.5 rounded">GET</span>
|
| 299 |
+
<span class="ml-2 font-mono">/api/cloud/status</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
</div>
|
| 301 |
+
<pre><code class="language-javascript">
|
| 302 |
+
// Response
|
| 303 |
+
{
|
| 304 |
+
"success": true,
|
| 305 |
+
"services": [
|
| 306 |
+
{
|
| 307 |
+
"provider": "AWS IoT",
|
| 308 |
+
"status": "connected",
|
| 309 |
+
"metrics": {
|
| 310 |
+
"messages": 1248,
|
| 311 |
+
"storage": 2.8,
|
| 312 |
+
"rulesProcessed": 56
|
| 313 |
+
}
|
| 314 |
+
},
|
| 315 |
+
{
|
| 316 |
+
"provider": "Azure Data Lake",
|
| 317 |
+
"status": "syncing",
|
| 318 |
+
"metrics": {
|
| 319 |
+
"dataStored": 4.2,
|
| 320 |
+
"lastSync": "2023-06-15T08:28:12.000Z",
|
| 321 |
+
"analyticsJobs": 12
|
| 322 |
+
}
|
| 323 |
+
},
|
| 324 |
+
{
|
| 325 |
+
"provider": "Google BigQuery",
|
| 326 |
+
"status": "processing",
|
| 327 |
+
"metrics": {
|
| 328 |
+
"queries": 84,
|
| 329 |
+
"mlModels": 3,
|
| 330 |
+
"storage": 1.5
|
| 331 |
+
}
|
| 332 |
+
}
|
| 333 |
+
]
|
| 334 |
+
}
|
| 335 |
+
</code></pre>
|
| 336 |
</div>
|
| 337 |
+
</div>
|
| 338 |
+
|
| 339 |
+
<div class="mb-8">
|
| 340 |
+
<h2 class="text-xl font-semibold text-gray-800 mb-4">Database Schema</h2>
|
| 341 |
|
| 342 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
| 343 |
+
<div class="bg-gray-50 p-4 rounded-lg">
|
| 344 |
+
<h3 class="font-medium text-gray-800 mb-2">User</h3>
|
| 345 |
+
<pre><code class="language-javascript">
|
| 346 |
+
{
|
| 347 |
+
name: String,
|
| 348 |
+
email: { type: String, unique: true },
|
| 349 |
+
password: String,
|
| 350 |
+
farmName: String,
|
| 351 |
+
role: { type: String, enum: ['user', 'admin'], default: 'user' },
|
| 352 |
+
createdAt: { type: Date, default: Date.now }
|
| 353 |
+
}
|
| 354 |
+
</code></pre>
|
| 355 |
</div>
|
| 356 |
+
|
| 357 |
+
<div class="bg-gray-50 p-4 rounded-lg">
|
| 358 |
+
<h3 class="font-medium text-gray-800 mb-2">Device</h3>
|
| 359 |
+
<pre><code class="language-javascript">
|
| 360 |
+
{
|
| 361 |
+
name: String,
|
| 362 |
+
type: { type: String, enum: ['moisture', 'temperature', 'humidity', 'light', 'ph', 'co2'] },
|
| 363 |
+
status: { type: String, enum: ['online', 'offline', 'maintenance'] },
|
| 364 |
+
batteryLevel: Number,
|
| 365 |
+
signalStrength: Number,
|
| 366 |
+
secretKey: String, // For authentication
|
| 367 |
+
userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
|
| 368 |
+
location: {
|
| 369 |
+
field: String,
|
| 370 |
+
coordinates: [Number] // [longitude, latitude]
|
| 371 |
+
}
|
| 372 |
+
}
|
| 373 |
+
</code></pre>
|
| 374 |
+
</div>
|
| 375 |
+
|
| 376 |
+
<div class="bg-gray-50 p-4 rounded-lg">
|
| 377 |
+
<h3 class="font-medium text-gray-800 mb-2">Reading</h3>
|
| 378 |
+
<pre><code class="language-javascript">
|
| 379 |
+
{
|
| 380 |
+
deviceId: { type: mongoose.Schema.Types.ObjectId, ref: 'Device' },
|
| 381 |
+
type: String,
|
| 382 |
+
value: Number,
|
| 383 |
+
timestamp: { type: Date, default: Date.now },
|
| 384 |
+
field: String,
|
| 385 |
+
blockchainHash: String
|
| 386 |
+
}
|
| 387 |
+
</code></pre>
|
| 388 |
+
</div>
|
| 389 |
+
|
| 390 |
+
<div class="bg-gray-50 p-4 rounded-lg">
|
| 391 |
+
<h3 class="font-medium text-gray-800 mb-2">Block</h3>
|
| 392 |
+
<pre><code class="language-javascript">
|
| 393 |
+
{
|
| 394 |
+
index: Number,
|
| 395 |
+
timestamp: { type: Date, default: Date.now },
|
| 396 |
+
data: {
|
| 397 |
+
deviceId: { type: mongoose.Schema.Types.ObjectId, ref: 'Device' },
|
| 398 |
+
readingType: String,
|
| 399 |
+
value: Number,
|
| 400 |
+
field: String
|
| 401 |
+
},
|
| 402 |
+
previousHash: String,
|
| 403 |
+
hash: String
|
| 404 |
+
}
|
| 405 |
+
</code></pre>
|
| 406 |
+
</div>
|
| 407 |
+
|
| 408 |
+
<div class="bg-gray-50 p-4 rounded-lg">
|
| 409 |
+
<h3 class="font-medium text-gray-800 mb-2">Prediction</h3>
|
| 410 |
+
<pre><code class="language-javascript">
|
| 411 |
+
{
|
| 412 |
+
type: { type: String, enum: ['irrigation', 'pest', 'harvest'] },
|
| 413 |
+
field: String,
|
| 414 |
+
prediction: String,
|
| 415 |
+
confidence: Number,
|
| 416 |
+
recommendation: String,
|
| 417 |
+
userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
|
| 418 |
+
createdAt: { type: Date, default: Date.now }
|
| 419 |
+
}
|
| 420 |
+
</code></pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
</div>
|
| 422 |
+
|
| 423 |
+
<div class="bg-gray-50 p-4 rounded-lg">
|
| 424 |
+
<h3 class="font-medium text-gray-800 mb-2">CloudService</h3>
|
| 425 |
+
<pre><code class="language-javascript">
|
| 426 |
+
{
|
| 427 |
+
provider: { type: String, enum: ['aws', 'azure', 'google'] },
|
| 428 |
+
status: String,
|
| 429 |
+
metrics: {
|
| 430 |
+
messages: Number,
|
| 431 |
+
storage: Number,
|
| 432 |
+
rulesProcessed: Number,
|
| 433 |
+
// ... other metrics
|
| 434 |
+
},
|
| 435 |
+
lastSync: Date,
|
| 436 |
+
userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }
|
| 437 |
+
}
|
| 438 |
+
</code></pre>
|
| 439 |
</div>
|
| 440 |
</div>
|
| 441 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
|
| 443 |
+
<div class="mb-8">
|
| 444 |
+
<h2 class="text-xl font-semibold text-gray-800 mb-4">Example Server Code</h2>
|
| 445 |
+
|
| 446 |
+
<div class="mb-6">
|
| 447 |
+
<h3 class="font-medium text-gray-800 mb-2">app.js (Main Server File)</h3>
|
| 448 |
+
<pre><code class="language-javascript">
|
| 449 |
+
require('dotenv').config();
|
| 450 |
+
const express = require('express');
|
| 451 |
+
const mongoose = require('mongoose');
|
| 452 |
+
const cors = require('cors');
|
| 453 |
+
const helmet = require('helmet');
|
| 454 |
+
const rateLimit = require('express-rate-limit');
|
| 455 |
+
const { Web3 } = require('web3');
|
| 456 |
+
const tf = require('@tensorflow/tfjs-node');
|
| 457 |
+
|
| 458 |
+
const app = express();
|
| 459 |
+
|
| 460 |
+
// Database connection
|
| 461 |
+
mongoose.connect(process.env.MONGODB_URI, {
|
| 462 |
+
useNewUrlParser: true,
|
| 463 |
+
useUnifiedTopology: true
|
| 464 |
+
})
|
| 465 |
+
.then(() => console.log('Connected to MongoDB'))
|
| 466 |
+
.catch(err => console.error('MongoDB connection error:', err));
|
| 467 |
+
|
| 468 |
+
// Middleware
|
| 469 |
+
app.use(cors());
|
| 470 |
+
app.use(helmet());
|
| 471 |
+
app.use(express.json());
|
| 472 |
+
|
| 473 |
+
// Rate limiting
|
| 474 |
+
const limiter = rateLimit({
|
| 475 |
+
windowMs: 15 * 60 * 1000, // 15 minutes
|
| 476 |
+
max: 100 // limit each IP to 100 requests per windowMs
|
| 477 |
+
});
|
| 478 |
+
app.use(limiter);
|
| 479 |
+
|
| 480 |
+
// Blockchain setup
|
| 481 |
+
const web3 = new Web3(process.env.BLOCKCHAIN_NODE_URL);
|
| 482 |
+
const contract = new web3.eth.Contract(
|
| 483 |
+
JSON.parse(process.env.CONTRACT_ABI),
|
| 484 |
+
process.env.CONTRACT_ADDRESS
|
| 485 |
+
);
|
| 486 |
+
|
| 487 |
+
// Routes
|
| 488 |
+
app.use('/api/auth', require('./routes/auth'));
|
| 489 |
+
app.use('/api/iot', require('./routes/iot'));
|
| 490 |
+
app.use('/api/blockchain', require('./routes/blockchain'));
|
| 491 |
+
app.use('/api/ai', require('./routes/ai'));
|
| 492 |
+
app.use('/api/cloud', require('./routes/cloud'));
|
| 493 |
+
|
| 494 |
+
// Error handling
|
| 495 |
+
app.use((err, req, res, next) => {
|
| 496 |
+
console.error(err.stack);
|
| 497 |
+
res.status(500).json({
|
| 498 |
+
success: false,
|
| 499 |
+
message: 'Internal server error'
|
| 500 |
+
});
|
| 501 |
+
});
|
| 502 |
+
|
| 503 |
+
const PORT = process.env.PORT || 5000;
|
| 504 |
+
app.listen(PORT, () => {
|
| 505 |
+
console.log(`Server running on port ${PORT}`);
|
| 506 |
+
});
|
| 507 |
+
|
| 508 |
+
module.exports = app;
|
| 509 |
+
</code></pre>
|
| 510 |
+
</div>
|
| 511 |
+
|
| 512 |
+
<div class="mb-6">
|
| 513 |
+
<h3 class="font-medium text-gray-800 mb-2">routes/iot.js (Example Route)</h3>
|
| 514 |
+
<pre><code class="language-javascript">
|
| 515 |
+
const express = require('express');
|
| 516 |
+
const router = express.Router();
|
| 517 |
+
const auth = require('../middleware/auth');
|
| 518 |
+
const Device = require('../models/Device');
|
| 519 |
+
const Reading = require('../models/Reading');
|
| 520 |
+
const { addBlock } = require('../utils/blockchain');
|
| 521 |
+
|
| 522 |
+
// @route GET api/iot/devices
|
| 523 |
+
// @desc Get all user's IoT devices
|
| 524 |
+
// @access Private
|
| 525 |
+
router.get('/devices', auth, async (req, res) => {
|
| 526 |
+
try {
|
| 527 |
+
const devices = await Device.find({ userId: req.user.id });
|
| 528 |
|
| 529 |
+
// Get latest readings for each device
|
| 530 |
+
const devicesWithReadings = await Promise.all(devices.map(async device => {
|
| 531 |
+
const latestReading = await Reading.findOne({ deviceId: device._id })
|
| 532 |
+
.sort({ timestamp: -1 })
|
| 533 |
+
.limit(1);
|
| 534 |
+
|
| 535 |
+
return {
|
| 536 |
+
...device.toObject(),
|
| 537 |
+
lastReading: latestReading || null
|
| 538 |
+
};
|
| 539 |
+
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 540 |
|
| 541 |
+
res.json({ success: true, devices: devicesWithReadings });
|
| 542 |
+
} catch (err) {
|
| 543 |
+
console.error(err.message);
|
| 544 |
+
res.status(500).json({ success: false, message: 'Server error' });
|
| 545 |
+
}
|
| 546 |
+
});
|
| 547 |
+
|
| 548 |
+
// @route POST api/iot/data
|
| 549 |
+
// @desc Receive data from IoT device
|
| 550 |
+
// @access Private (using device secret key)
|
| 551 |
+
router.post('/data', async (req, res) => {
|
| 552 |
+
const { deviceId, secretKey, readings } = req.body;
|
| 553 |
+
|
| 554 |
+
try {
|
| 555 |
+
// Verify device
|
| 556 |
+
const device = await Device.findOne({ _id: deviceId, secretKey });
|
| 557 |
+
if (!device) {
|
| 558 |
+
return res.status(401).json({
|
| 559 |
+
success: false,
|
| 560 |
+
message: 'Invalid device credentials'
|
| 561 |
+
});
|
| 562 |
+
}
|
| 563 |
|
| 564 |
+
// Save readings
|
| 565 |
+
const savedReadings = await Promise.all(readings.map(async reading => {
|
| 566 |
+
const newReading = new Reading({
|
| 567 |
+
deviceId,
|
| 568 |
+
type: reading.type,
|
| 569 |
+
value: reading.value,
|
| 570 |
+
timestamp: reading.timestamp || Date.now(),
|
| 571 |
+
field: device.location.field
|
| 572 |
+
});
|
| 573 |
|
| 574 |
+
// Add to blockchain
|
| 575 |
+
const blockData = {
|
| 576 |
+
deviceId,
|
| 577 |
+
readingType: reading.type,
|
| 578 |
+
value: reading.value,
|
| 579 |
+
field: device.location.field
|
|
|
|
|
|
|
| 580 |
};
|
| 581 |
|
| 582 |
+
const hash = await addBlock(blockData);
|
| 583 |
+
newReading.blockchainHash = hash;
|
| 584 |
+
|
| 585 |
+
return await newReading.save();
|
| 586 |
+
}));
|
| 587 |
+
|
| 588 |
+
// Update device status and battery if provided
|
| 589 |
+
if (readings[0].batteryLevel) {
|
| 590 |
+
device.batteryLevel = readings[0].batteryLevel;
|
| 591 |
+
await device.save();
|
| 592 |
}
|
| 593 |
|
| 594 |
+
res.json({
|
| 595 |
+
success: true,
|
| 596 |
+
message: 'Data received and stored',
|
| 597 |
+
blockchainHash: savedReadings[0].blockchainHash
|
| 598 |
+
});
|
| 599 |
+
} catch (err) {
|
| 600 |
+
console.error(err.message);
|
| 601 |
+
res.status(500).json({ success: false, message: 'Server error' });
|
| 602 |
+
}
|
| 603 |
+
});
|
| 604 |
+
|
| 605 |
+
module.exports = router;
|
| 606 |
+
</code></pre>
|
| 607 |
+
</div>
|
| 608 |
+
|
| 609 |
+
<div class="mb-6">
|
| 610 |
+
<h3 class="font-medium text-gray-800 mb-2">utils/blockchain.js</h3>
|
| 611 |
+
<pre><code class="language-javascript">
|
| 612 |
+
const Block = require('../models/Block');
|
| 613 |
+
const crypto = require('crypto');
|
| 614 |
+
|
| 615 |
+
// Simple blockchain implementation (in production would use Ethereum or similar)
|
| 616 |
+
class Blockchain {
|
| 617 |
+
constructor() {
|
| 618 |
+
this.chain = [];
|
| 619 |
+
this.initializeChain();
|
| 620 |
+
}
|
| 621 |
+
|
| 622 |
+
async initializeChain() {
|
| 623 |
+
// Load existing chain from database
|
| 624 |
+
const blocks = await Block.find().sort({ index: 1 });
|
| 625 |
+
this.chain = blocks;
|
| 626 |
|
| 627 |
+
// If no blocks, create genesis block
|
| 628 |
+
if (this.chain.length === 0) {
|
| 629 |
+
await this.createGenesisBlock();
|
| 630 |
+
}
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
async createGenesisBlock() {
|
| 634 |
+
const genesisBlock = new Block({
|
| 635 |
+
index: 0,
|
| 636 |
+
timestamp: Date.now(),
|
| 637 |
+
data: { message: "Genesis block" },
|
| 638 |
+
previousHash: "0",
|
| 639 |
+
hash: this.calculateHash(0, "0", Date.now(), { message: "Genesis block" })
|
| 640 |
+
});
|
| 641 |
|
| 642 |
+
await genesisBlock.save();
|
| 643 |
+
this.chain.push(genesisBlock);
|
| 644 |
+
}
|
| 645 |
+
|
| 646 |
+
calculateHash(index, previousHash, timestamp, data) {
|
| 647 |
+
return crypto
|
| 648 |
+
.createHash('sha256')
|
| 649 |
+
.update(index + previousHash + timestamp + JSON.stringify(data))
|
| 650 |
+
.digest('hex');
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
async addBlock(data) {
|
| 654 |
+
const previousBlock = this.chain[this.chain.length - 1];
|
| 655 |
+
const newIndex = previousBlock.index + 1;
|
| 656 |
+
const newTimestamp = Date.now();
|
| 657 |
+
const newHash = this.calculateHash(newIndex, previousBlock.hash, newTimestamp, data);
|
| 658 |
+
|
| 659 |
+
const newBlock = new Block({
|
| 660 |
+
index: newIndex,
|
| 661 |
+
timestamp: newTimestamp,
|
| 662 |
+
data,
|
| 663 |
+
previousHash: previousBlock.hash,
|
| 664 |
+
hash: newHash
|
| 665 |
+
});
|
| 666 |
+
|
| 667 |
+
await newBlock.save();
|
| 668 |
+
this.chain.push(newBlock);
|
| 669 |
+
|
| 670 |
+
return newHash;
|
| 671 |
+
}
|
| 672 |
+
|
| 673 |
+
async validateChain() {
|
| 674 |
+
for (let i = 1; i < this.chain.length; i++) {
|
| 675 |
+
const currentBlock = this.chain[i];
|
| 676 |
+
const previousBlock = this.chain[i - 1];
|
| 677 |
|
| 678 |
+
// Check hash
|
| 679 |
+
if (currentBlock.hash !== this.calculateHash(
|
| 680 |
+
currentBlock.index,
|
| 681 |
+
currentBlock.previousHash,
|
| 682 |
+
currentBlock.timestamp,
|
| 683 |
+
currentBlock.data
|
| 684 |
+
)) {
|
| 685 |
+
return false;
|
| 686 |
+
}
|
|
|
|
|
|
|
| 687 |
|
| 688 |
+
// Check previous hash
|
| 689 |
+
if (currentBlock.previousHash !== previousBlock.hash) {
|
| 690 |
+
return false;
|
| 691 |
+
}
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
return true;
|
| 695 |
+
}
|
| 696 |
+
}
|
| 697 |
+
|
| 698 |
+
const blockchain = new Blockchain();
|
| 699 |
+
|
| 700 |
+
// Public functions
|
| 701 |
+
const addBlock = async (data) => {
|
| 702 |
+
return await blockchain.addBlock(data);
|
| 703 |
+
};
|
| 704 |
+
|
| 705 |
+
const validateChain = async () => {
|
| 706 |
+
return await blockchain.validateChain();
|
| 707 |
+
};
|
| 708 |
+
|
| 709 |
+
const getBlocks = async () => {
|
| 710 |
+
return blockchain.chain;
|
| 711 |
+
};
|
| 712 |
+
|
| 713 |
+
module.exports = {
|
| 714 |
+
addBlock,
|
| 715 |
+
validateChain,
|
| 716 |
+
getBlocks
|
| 717 |
+
};
|
| 718 |
+
</code></pre>
|
| 719 |
+
</div>
|
| 720 |
+
</div>
|
| 721 |
+
|
| 722 |
+
<div class="mb-8">
|
| 723 |
+
<h2 class="text-xl font-semibold text-gray-800 mb-4">Deployment</h2>
|
| 724 |
|
| 725 |
+
<div class="mb-6">
|
| 726 |
+
<h3 class="font-medium text-gray-800 mb-2">Dockerfile</h3>
|
| 727 |
+
<pre><code class="language-dockerfile">
|
| 728 |
+
# Use official Node.js image
|
| 729 |
+
FROM node:18-alpine
|
| 730 |
+
|
| 731 |
+
# Create app directory
|
| 732 |
+
WORKDIR /usr/src/app
|
| 733 |
+
|
| 734 |
+
# Install app dependencies
|
| 735 |
+
COPY package*.json ./
|
| 736 |
+
RUN npm install
|
| 737 |
+
|
| 738 |
+
# Bundle app source
|
| 739 |
+
COPY . .
|
| 740 |
+
|
| 741 |
+
# Build the app
|
| 742 |
+
RUN npm run build
|
| 743 |
+
|
| 744 |
+
# Expose the app port
|
| 745 |
+
EXPOSE 5000
|
| 746 |
+
|
| 747 |
+
# Start the app
|
| 748 |
+
CMD ["npm", "start"]
|
| 749 |
+
</code></pre>
|
| 750 |
+
</div>
|
| 751 |
|
| 752 |
+
<div class="mb-6">
|
| 753 |
+
<h3 class="font-medium text-gray-800 mb-2">docker-compose.yml</h3>
|
| 754 |
+
<pre><code class="language-yaml">
|
| 755 |
+
version: '3.8'
|
| 756 |
+
|
| 757 |
+
services:
|
| 758 |
+
app:
|
| 759 |
+
build: .
|
| 760 |
+
ports:
|
| 761 |
+
- "5000:5000"
|
| 762 |
+
environment:
|
| 763 |
+
- NODE_ENV=production
|
| 764 |
+
- MONGODB_URI=mongodb://mongo:27017/agrichain
|
| 765 |
+
- JWT_SECRET=your_jwt_secret
|
| 766 |
+
depends_on:
|
| 767 |
+
- mongo
|
| 768 |
+
restart: unless-stopped
|
| 769 |
+
|
| 770 |
+
mongo:
|
| 771 |
+
image: mongo:6.0
|
| 772 |
+
ports:
|
| 773 |
+
- "27017:27017"
|
| 774 |
+
volumes:
|
| 775 |
+
- mongodb_data:/data/db
|
| 776 |
+
environment:
|
| 777 |
+
- MONGO_INITDB_ROOT_USERNAME=root
|
| 778 |
+
- MONGO_INITDB_ROOT_PASSWORD=example
|
| 779 |
+
|
| 780 |
+
volumes:
|
| 781 |
+
mongodb_data:
|
| 782 |
+
</code></pre>
|
| 783 |
+
</div>
|
| 784 |
|
| 785 |
+
<div class="mb-6">
|
| 786 |
+
<h3 class="font-medium text-gray-800 mb-2">Kubernetes Deployment</h3>
|
| 787 |
+
<pre><code class="language-yaml">
|
| 788 |
+
apiVersion: apps/v1
|
| 789 |
+
kind: Deployment
|
| 790 |
+
metadata:
|
| 791 |
+
name: agrichain-backend
|
| 792 |
+
spec:
|
| 793 |
+
replicas: 3
|
| 794 |
+
selector:
|
| 795 |
+
matchLabels:
|
| 796 |
+
app: agrichain-backend
|
| 797 |
+
template:
|
| 798 |
+
metadata:
|
| 799 |
+
labels:
|
| 800 |
+
app: agrichain-backend
|
| 801 |
+
spec:
|
| 802 |
+
containers:
|
| 803 |
+
- name: app
|
| 804 |
+
image: your-registry/agrichain-backend:latest
|
| 805 |
+
ports:
|
| 806 |
+
- containerPort: 5000
|
| 807 |
+
env:
|
| 808 |
+
- name: NODE_ENV
|
| 809 |
+
value: production
|
| 810 |
+
- name: MONGODB_URI
|
| 811 |
+
value: "mongodb://agrichain-mongo:27017/agrichain"
|
| 812 |
+
- name: JWT_SECRET
|
| 813 |
+
valueFrom:
|
| 814 |
+
secretKeyRef:
|
| 815 |
+
name: agrichain-secrets
|
| 816 |
+
key: jwt-secret
|
| 817 |
+
- name: mongo
|
| 818 |
+
image: mongo:6.0
|
| 819 |
+
ports:
|
| 820 |
+
- containerPort: 27017
|
| 821 |
+
env:
|
| 822 |
+
- name: MONGO_INITDB_ROOT_USERNAME
|
| 823 |
+
valueFrom:
|
| 824 |
+
secretKeyRef:
|
| 825 |
+
name: agrichain-secrets
|
| 826 |
+
key: mongo-root-username
|
| 827 |
+
- name: MONGO_INITDB_ROOT_PASSWORD
|
| 828 |
+
valueFrom:
|
| 829 |
+
secretKeyRef:
|
| 830 |
+
name: agrichain-secrets
|
| 831 |
+
key: mongo-root-password
|
| 832 |
+
volumeMounts:
|
| 833 |
+
- name: mongodb-data
|
| 834 |
+
mountPath: /data/db
|
| 835 |
+
volumes:
|
| 836 |
+
- name: mongodb-data
|
| 837 |
+
persistentVolumeClaim:
|
| 838 |
+
claimName: mongodb-pvc
|
| 839 |
+
|
| 840 |
+
---
|
| 841 |
+
apiVersion: v1
|
| 842 |
+
kind: Service
|
| 843 |
+
metadata:
|
| 844 |
+
name: agrichain-service
|
| 845 |
+
spec:
|
| 846 |
+
selector:
|
| 847 |
+
app: agrichain-backend
|
| 848 |
+
ports:
|
| 849 |
+
- protocol: TCP
|
| 850 |
+
port: 80
|
| 851 |
+
targetPort: 5000
|
| 852 |
+
type: LoadBalancer
|
| 853 |
+
</code></pre>
|
| 854 |
+
</div>
|
| 855 |
+
</div>
|
| 856 |
|
| 857 |
+
<div class="bg-emerald-50 p-4 rounded-lg">
|
| 858 |
+
<h2 class="text-lg font-medium text-emerald-800 mb-2">Next Steps</h2>
|
| 859 |
+
<ul class="list-disc pl-5 text-gray-700 space-y-1">
|
| 860 |
+
<li>Set up CI/CD pipeline with GitHub Actions</li>
|
| 861 |
+
<li>Configure monitoring with Prometheus and Grafana</li>
|
| 862 |
+
<li>Implement WebSocket for real-time updates to frontend</li>
|
| 863 |
+
<li>Add more AI models for different crop types</li>
|
| 864 |
+
<li>Integrate with weather APIs for enhanced predictions</li>
|
| 865 |
+
</ul>
|
| 866 |
+
</div>
|
| 867 |
+
</div>
|
| 868 |
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Abder004/smartfarming" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 869 |
</html>
|