Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Abhi5415/auxilium into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
ShehryarX committed Sep 8, 2019
2 parents a39ce0c + e0b33f0 commit 6c7e5e6
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 92 deletions.
10 changes: 7 additions & 3 deletions auxilium-atm/ir_sensor.py
Expand Up @@ -21,17 +21,18 @@
f.write("pending")
f.close()

print("pending")
while True:
sensor_state = GPIO.input(irPIN)

if sensor_state and not last_state:
inactive = False
print('connected')
# print('connected')

elif not sensor_state and last_state:
coinsDeposited += 1
inactive = False
print('broken')
# print('broken')

if not inactive:
timeStarted = time.time()
Expand All @@ -44,8 +45,11 @@
last_state = sensor_state

print(coinsDeposited)

f = open("deposit.txt","w+")
f.write(str(coinsDeposited))
f.close()

finally:
GPIO.cleanup()
sys.stdout.flush()
GPIO.cleanup()
63 changes: 34 additions & 29 deletions auxilium-atm/server.js
@@ -1,46 +1,51 @@
const express = require('express');
const bodyParser = require('body-parser');
const shell = require('shelljs');
const fs = require('fs');
const app = express();

const fs = requir
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.get('/api/atm/deposit', (req, res) => {
shell.exec('python ir_sensor.py');
const spawn = require("child_process").spawn;
const pythonProcess = spawn('python', ["ir_sensor.py"]);

while (true) {
fs.readFile('./deposit.txt', 'utf8', (err, contents) => {
if (contents != 'pending') {
console.log('complete');
res.status(200).send({
count: parseInt(contents)
});
return;
}
});
fs.close()
setTimeout(() => { }, 5000);
}
pythonProcess.stdout.on('data', (data) => {
var prints = data.toString('utf8');
prints = prints.split('\n');
if (prints.length == 1) {
res.status(500).send()
} else if (prints.length >= 2) {
res.status(200).send({
count: prints[1]
})
}
});
});

app.get('/api/atm/depositPersisted', (req, res) => {
fs.readFile('./deposit.txt', 'utf8', (err, data) => {
res.status(200).send({
count: parseInt(data)
})
});
});

app.post('/api/atm/withdraw', (req, res) => {
var rotations = req.body.amount;

if (rotations > 0) {
shell.exec(`python servo.py ${rotations}`);
while (true) {
fs.readFile('./withdraw.txt', 'utf8', (err, contents) => {
if (contents != 'pending') {
console.log('complete');
res.status(202).send();
return;
}
});
fs.close();
setTimeout(() => { }, 5000);
}
const spawn = require("child_process").spawn;
const pythonProcess = spawn('python', ["servo.py", rotations]);

pythonProcess.stdout.on('data', (data) => {
var prints = data.toString('utf8');
prints = prints.split('\n');
if (prints.length == 1) {
res.status(400).send()
} else if (prints.length >= 2) {
res.status(200).send()
}
});
} else {
res.status(400).send();
}
Expand Down
19 changes: 6 additions & 13 deletions auxilium-atm/servo.py
Expand Up @@ -9,26 +9,19 @@
p = GPIO.PWM(servoPIN, 50)
p.start(12.5)

f = open("withdraw.txt", "w+")
f.write("pending")
f.close()

rotations = 0

if len(sys.argv) > 1:
rotations = int(sys.argv[1])

try:
print("pending")
for i in range(rotations):
p.ChangeDutyCycle(9.6)
time.sleep(0.5)
print("spin")
p.ChangeDutyCycle(12.5)
time.sleep(0.5)

f = open("withdraw.txt", "w+")
f.write("done")
f.close()
p.ChangeDutyCycle(9.6)
time.sleep(0.5)
p.ChangeDutyCycle(12.5)
time.sleep(0.5)
print("done")
p.stop()
GPIO.cleanup()

Expand Down
96 changes: 49 additions & 47 deletions auxilium-server/controllers/stellar.js
@@ -1,67 +1,69 @@
const StellarSdk = require("stellar-sdk");
const StellarSdk = require('stellar-sdk');
StellarSdk.Network.useTestNetwork();
const server = new StellarSdk.Server("https://horizon-testnet.stellar.org");
const validate = require("jsonschema").validate;
const server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
const validate = require('jsonschema').validate;

const publicKey = "GAI6C5X6QK5KE3OXXIQAUZ33WCMCENCJ5VDYRKNZCR6LCYRM5PSQGFOG";
const secretString = "SALEHVAPOGW677KLEDFNQZ3WA7JSQCN2UJ37CUXHZOXIKHPEOOV264L7";
const publicKey = 'GAI6C5X6QK5KE3OXXIQAUZ33WCMCENCJ5VDYRKNZCR6LCYRM5PSQGFOG';
const secretString = 'SALEHVAPOGW677KLEDFNQZ3WA7JSQCN2UJ37CUXHZOXIKHPEOOV264L7';

// let transactionExample = {
// u: "41614",
// a: -1234
// };

exports.submitTransaction = async payload => {
try {
const account = await server.loadAccount(publicKey);
const fee = await server.fetchBaseFee();
const memo = new StellarSdk.Memo.text(JSON.stringify(payload));
try {
const account = await server.loadAccount(publicKey);
const fee = await server.fetchBaseFee();
const memo = new StellarSdk.Memo.text(JSON.stringify(payload));

const transaction = new StellarSdk.TransactionBuilder(account, {
fee,
memo
})
.addOperation(
StellarSdk.Operation.payment({
destination: publicKey,
asset: StellarSdk.Asset.native(),
amount: "0.0000001"
})
)
.setTimeout(30)
.build();
const transaction = new StellarSdk.TransactionBuilder(account, {
fee,
memo,
})
.addOperation(
StellarSdk.Operation.payment({
destination: publicKey,
asset: StellarSdk.Asset.native(),
amount: '0.0000001',
})
)
.setTimeout(30)
.build();

transaction.sign(StellarSdk.Keypair.fromSecret(secretString));
transaction.sign(StellarSdk.Keypair.fromSecret(secretString));

const transactionResult = await server.submitTransaction(transaction);
const transactionResult = await server.submitTransaction(transaction);

console.log(transactionResult);
} catch (err) {
console.error(err);
}
console.log(transactionResult);
} catch (err) {
console.error(err);
}
};

exports.getTransactions = async () => {
let history = [];
let history = [];

r = await server
.transactions()
.limit(1)
.forAccount(publicKey)
.call();
while (r.records.length != 0) {
let record = r.records[0];
r = await server
.transactions()
.limit(1)
.forAccount(publicKey)
.call();
while (r.records.length != 0) {
let record = r.records[0];

if (
record.hasOwnProperty("memo") &&
validate(record, { type: "object" }).errors.length == 0
) {
let parsedRecord = JSON.parse(record.memo);
parsedRecord.r = record._links.self.href;
history.push(parsedRecord);
}
if (
record.hasOwnProperty('memo') &&
validate(record, { type: 'object' }).errors.length == 0
) {
let parsedRecord = JSON.parse(record.memo);
parsedRecord.r = record._links.self.href;
history.push(parsedRecord);
}

r = await r.next();
}
return history;
r = await r.next();
}
return history;
};

exports.getTransactions();

0 comments on commit 6c7e5e6

Please sign in to comment.