Skip to content

Commit

Permalink
cosmetic updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rideam committed May 21, 2023
1 parent 3757204 commit a4a11ca
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ static/bootstrap/bootstrap4
*/.env
tests/data
tests/geckodriver.log
tests/users.py
tests/users.py
tests/misc/
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ CONFIG_CLASS =config.DevelopmentConfig

The detailed app description is [here](/docs/README.md)

## License

Copyright 2023 Tatenda Muvhu

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
3 changes: 2 additions & 1 deletion microcontroller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ Replace the credentials in `creds.py` with your own
```python
ssid='your_wifi_ssid'
pwd='your_password'
endpoint='url_where_app_is_deployed eg https://playground.com'
endpoint='url_where_app_is_deployed'
wallet='farmer_wallet_address'
```
3 changes: 2 additions & 1 deletion microcontroller/creds.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ssid=''
pwd=''
endpoint=''
endpoint=''
wallet=''
5 changes: 2 additions & 3 deletions microcontroller/dth11.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ def get_temp_hum():
sensor.measure()
t = sensor.temperature()
h = sensor.humidity()
print('Temperature: %3.1f C' % t)
print('Humidity: %3.1f %%' % h)
return t, h
except OSError as e:
print('Sensor Reading Failed')
print('Sensor Reading Failed')

21 changes: 11 additions & 10 deletions microcontroller/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,33 @@ def connect_wifi():
time.sleep(2)

if wifi.isconnected():
print('Connected')
print('Wifi Connected')
else:
print('Timed Out')

print('Connection Timed Out')
return wifi


def get_data():
temperature, humidity = dht11.get_temp_hum()
# soil_m = soil_moisture.get_soil_moisture()
soil_m = soil_moisture.get_soil_moisture()

post_data = ujson.dumps({
'temperature': temperature,
'humidity': humidity,
'soil_moisture': 50,
'soil_moisture': soil_m,
'farm': 'Puma Farm',
'crop': 'Maize',
'user': 'IZT2EGJMVWLUMZ56FM2NK7YVKUTDCGHUQ5KNRWMJQRY4K6ZSOGU6K4J464'
'user': creds.wallet
})
request_url = creds.endpoint + '/weather'
# request_url = creds.endpoint + '/ping'
print(request_url)
try:
print('Temperature: %3.1f C' % temperature)
print('Humidity: %3.1f %%' % humidity)
print('Soil Moisture: %3.1f %%' % soil_m)
res = urequests.post(request_url, headers={'content-type': 'application/json'}, data=post_data)
# print(res.json)
print(f'Data posted successfully {res.json}')
except Exception as e:
print(e)
print(f'\nError posting data {e}')


def main():
Expand All @@ -60,3 +60,4 @@ def main():


main()

10 changes: 4 additions & 6 deletions microcontroller/soil_moisture.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

def get_soil_moisture():
soil = ADC(Pin(15))

min_m = 0
max_m = 65535

soil.atten(ADC.ATTN_11DB)
min_m = 17000
max_m = 40000
moisture = (max_m - soil.read_u16()) * 100 / (max_m - min_m)
print(" moisture : " + "%.2f" % moisture + " % (adc : " + str(soil.read_u16()) + ")")
return moisture
return float(moisture)
4 changes: 4 additions & 0 deletions static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ th, td {
margin-top: 2.5rem;
}

.mb-4 {
margin-top: 2.5rem;
}

.mt-5 {
margin-top: 3.5rem;
}
Expand Down
5 changes: 5 additions & 0 deletions templates/bootstrap3/sensordata.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

{% block content %}
<div class="mt-4">
<div style="display: flex; flex-direction: row">
<b>Address:</b>
<p style="margin-left: 1rem">{{ address }}</p>
</div>

<h4>Sensor Data</h4>

<canvas id="chart" height="400" style="width: 100%"></canvas>
Expand Down
16 changes: 9 additions & 7 deletions tests/locustfile.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from locust import HttpUser, task, between
from locust import HttpUser, task

import env
import users


class TestUser(HttpUser):
wait_time = between(1, 5)
# wait_time = between(1, 5)
host = env.host

def on_start(self):
self.user = users.users.pop()

@task(1)
def index(self):
self.client.get("/login")
def transactionstest(self):
self.client.post("/transactiontest", json=self.user )

@task(2)
def farm_data(self):
self.client.get("/farmdata?farm=puma")
12 changes: 6 additions & 6 deletions tests/login_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def setUp(self):
self.driver = webdriver.Chrome(options=options)

def test_login(self):
driver = self.driver
driver.get(f"{env.host}/login")
self.assertIn("Index Insurance", driver.title)
elem = driver.find_element(By.NAME, "passphrase")
# driver = self.driver
self.driver.get(f"{env.host}/login")
self.assertIn("Index Insurance", self.driver.title)
elem = self.driver.find_element(By.NAME, "passphrase")
elem.send_keys(env.account_two_memonic)
elem.send_keys(Keys.RETURN)
self.assertIn("Account Details", driver.page_source)
self.assertIn(env.account_two_address, driver.page_source)
self.assertIn("Account Details", self.driver.page_source)
self.assertIn(env.account_two_address, self.driver.page_source)

def tearDown(self):
self.driver.close()
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def sensordata():
.all()
return render_template(
'sensordata.html',
farm_weather_data=[f.as_dict() for f in farm_weather_data]
farm_weather_data=[f.as_dict() for f in farm_weather_data],
address=current_user.public_key
)


Expand Down

0 comments on commit a4a11ca

Please sign in to comment.