Get the exact same results. The Arduino shows in both.
Thanks,
Carl
text = serial.Serial(port='/dev/tty.usbmodemfd541', baudrate=9600)
text.open()
text.write('b')
text.close()
Tenaga:~ mike$ curl arduino5/mtds -d curl=1
Sensor 1 : 16.7
Sensor 5 : 10.5
Sensor 6 : 8.1
OK
Tenaga:~ mike$
Tenaga:~ mike$ cat /etc/hosts
##
# Host Database
#
...
10.0.1.177 arduino1
10.0.1.204 arduino4
10.0.1.215 arduino5
--Update MTDS variables
set physicalSensors to {"Basement", "Outside", "undefined", "undefined", "Garage", "Attic", "Office", "MasterBR"}
set wdsData to ""
try -- read data from MTDS devices
set wdsData to (do shell script "curl arduino5/mtds -d curl=1")
end try
set nP to ((count of paragraphs in wdsData) as number) - 1
repeat while nP > 0
set sensor to (word 2 of paragraph nP of wdsData) as integer
set tNumber to ((word 3 of paragraph nP of wdsData) as number)
if paragraph nP of wdsData contains "-" then -- tNumber should be negative
set tNumber to (tNumber * (-1.0))
end if
set tString to ((tNumber as text) & "°")
set varname1 to (item sensor of physicalSensors) & "_Temperature"
set varname2 to "t" & (item sensor of physicalSensors)
tell application "IndigoServer"
set value of variable varname1 to tString
set value of variable varname2 to tNumber
end tell
set nP to nP - 1
end repeat
/*
* MTDS_v2_1.ino
* Mike Lussier - Jan 31, 2013
* Compiled with Arduino 1.0.3
*
* This is version 2.1
* Status: compiles, executes and works well with multiple sensors.
*****************************************
* Uses serial monitor at 19200 baud to configure sensors
*****************************************
* v2.1.x - Starting point is v2.0.
* - - -
* .3 - Recompiled with latest version of Arduino sdk 1.0.3. Size 25,746 bytes.
*/
#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"
#include "tSensor.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define INO_NAME "MTDS"
#define INO_VERSION "2.1.3"
#define N_SENSORS 6 // Maximum number of sensors on this bus
///////////////////////////////////////////////////////////////////////////
#define ARDUINO_UNIT_NO 5 // Arduino unit number (4 or 5) /
///////////////////////////////////////////////////////////////////////////
// URLs on this server will start with arduino.../mtds
#define PREFIX "/mtds"
// Create an instance of the webserver
WebServer webserver(PREFIX, 80);
// NVRAM storage
P(ack) = "OK";
// Digital pin assignments
#define ONE_WIRE_BUS 8 // 1-Wire data
#define TEMPERATURE_PRECISION 10 // Use 10-bit resolution for DS18B20s
// Setup a oneWire instance to communicate with OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to the Dallas Temperature Library
DallasTemperature sensors(&oneWire);
// Allocate sensor data arrays
const short nSensors = N_SENSORS;
tSensor sensor[nSensors];
// Variables
int nDevices; // Number of 1-wire devices found on bus
short nReadings = 0; // Number of readings accumulated for averaging
DeviceAddress ithDeviceAddress; // Address of ith device
short mtdsFcn = 0; // Web server function index
char cstat[80]; // Used to hold formatted text
// Constants
const short maxReadings = 5; // Number of temperature readings needed to compute average
// Global time vars
unsigned long t0 = 0, sec = 0;
int nticks = 0, hourNo = 0, dayNo = 0;
//******* Webserver Functions ********
void mtdsCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
char ctime[10];
bool curlClient = false;
if (type == WebServer::POST)
{
bool repeat;
char name[16], value[16];
repeat = server.readPOSTparam(name, 16, value, 16);
// curl client will use "curl" to prefix an mtds command
if (strcmp(name, "curl") == 0) {
curlClient = true;
mtdsFcn = strtoul(value, NULL, 10);
// Carry out mtds functions
switch (mtdsFcn) {
case 1: // Post current readings for all online sensors
{
postAll();
// Post OK
server.printP(ack);
server.printCRLF();
break;
}
case 0: // Post unit status and details
{
// Unit identity
sprintf(cstat,"unit_no : %d", ARDUINO_UNIT_NO);
server.println(cstat);
sprintf(cstat,"devices : %d", nDevices);
server.println(cstat);
// Time counters
sprintf(ctime,"days_up : %d", dayNo);
server.println(ctime);
sprintf(ctime,"seconds : %lu", sec);
server.println(ctime);
// Software details
sprintf(cstat,"ino_name : %s", INO_NAME);
server.print(cstat);
sprintf(cstat," %s", INO_VERSION);
server.println(cstat);
// Post OK
server.printP(ack);
server.printCRLF();
break;
}
case 9: // Re-sync uptime (called by the Indigo scheduler at midnight)
{
if (hourNo >= 18) dayNo++;
hourNo = 0;
sec = 0;
sprintf(cstat,"%s", "Synced.");
server.println(cstat);
// Post OK
server.printP(ack);
server.printCRLF();
break;
}
} // switch
}
return;
} // if type is POST
// For a HEAD or GET, send the standard "OK headers"
server.httpSuccess();
} // mtdsCmd
//******* Sensor Functions ********
void configureSensors()
// Devices are mapped to sensors via their address
{
// Assign default addresses (00-00-00-00-00-00-00-00)
for (int j=0;j<nSensors;j++){
for (int i=0;i<8;i++){
sensor[j].add[i] = 0x00;
}
}
#if ARDUINO_UNIT_NO == 5
// Logical Sensor1 28-C4-70-D7-03-00-00-53
sensor[0].add[0]=0x28;
sensor[0].add[1]=0xC4;
sensor[0].add[2]=0x70;
sensor[0].add[3]=0xD7;
sensor[0].add[4]=0x03;
sensor[0].add[5]=0x00;
sensor[0].add[6]=0x00;
sensor[0].add[7]=0x53;
// Logical Sensor2 10-B8-A1-0A-02-08-00-81
sensor[1].add[0]=0x10;
sensor[1].add[1]=0xB8;
sensor[1].add[2]=0xA1;
sensor[1].add[3]=0x0A;
sensor[1].add[4]=0x02;
sensor[1].add[5]=0x08;
sensor[1].add[6]=0x00;
sensor[1].add[7]=0x81;
// Logical Sensor3 - offline
// Logical Sensor4 - offline
// Logical Sensor5 28-27-9C-D7-03-00-00-D8
sensor[4].add[0]=0x28;
sensor[4].add[1]=0x27;
sensor[4].add[2]=0x9C;
sensor[4].add[3]=0xD7;
sensor[4].add[4]=0x03;
sensor[4].add[5]=0x00;
sensor[4].add[6]=0x00;
sensor[4].add[7]=0xD8;
// Logical Sensor6 28-38-72-D7-03-00-00-DF
sensor[5].add[0]=0x28;
sensor[5].add[1]=0x38;
sensor[5].add[2]=0x72;
sensor[5].add[3]=0xD7;
sensor[5].add[4]=0x03;
sensor[5].add[5]=0x00;
sensor[5].add[6]=0x00;
sensor[5].add[7]=0xDF;
// Logical Sensor7 - offline
// Logical Sensor8 - offline
#endif
// Physical to logical sensor names
#if ARDUINO_UNIT_NO == 5
sprintf(sensor[0].nam,"%s","Sensor 1");
sprintf(sensor[1].nam,"%s","Sensor 2");
sprintf(sensor[2].nam,"%s","Sensor 3");
sprintf(sensor[3].nam,"%s","Sensor 4");
sprintf(sensor[4].nam,"%s","Sensor 5");
sprintf(sensor[5].nam,"%s","Sensor 6");
//sprintf(sensor[6].nam,"%s","Sensor 7");
//sprintf(sensor[7].nam,"%s","Sensor 8");
#endif
// Status (offline, online)
// All offline by default; changed by setup()
for (int k=0;k<nSensors;k++) sensor[k].sta = offline;
// Grab a count of devices on the wire
nDevices = sensors.getDeviceCount();
// Locate devices on the bus
Serial.print("Locating devices...");
Serial.print("found ");
Serial.print(nDevices, DEC);
if (nDevices == 1) Serial.println(" device on the 1-wire bus.");
else Serial.println(" devices on the 1-wire bus.");
// Report parasitic power requirements
Serial.print("Parasitic power mode is ");
if (sensors.isParasitePowerMode()) Serial.println("ON");
else Serial.println("OFF");
Serial.println();
Serial.print("Arduino unit no: ");
Serial.println(ARDUINO_UNIT_NO);
// Loop through each device, print out address, matching logical sensor name,
// temperature resolution
for(int i=0;i<nDevices;i++)
{
Serial.println("---------------------------------------------------");
// Search the wire for address of ith sensor
if(sensors.getAddress(ithDeviceAddress, i))
{
Serial.print("Found device ");
Serial.print(i, DEC);
Serial.print(" of type ");
if (ithDeviceAddress[0] == 0x10) Serial.print("DS18S20");
else if (ithDeviceAddress[0] == 0x28) Serial.print("DS18B20");
else Serial.print("UNKNOWN");
Serial.print(" with address ");
printAddress(ithDeviceAddress);
// Find matching sensor
short ithSensor = getIndex(ithDeviceAddress);
if (ithSensor >= 0) {
Serial.print(" - Mapped to ");
Serial.println(sensor[ithSensor].nam);
// Set sensor's dev attribute to device index
sensor[ithSensor].dev = i;
// Reset accumulator for sensor
sensor[ithSensor].acc = 0.0;
// Set sensor status to online
sensor[ithSensor].sta = online;
Serial.print("Setting resolution to ");
Serial.println(TEMPERATURE_PRECISION, DEC);
// Set the resolution to TEMPERATURE_PRECISION bit
sensors.setResolution(ithDeviceAddress, TEMPERATURE_PRECISION);
Serial.print("Resolution actually set to ");
Serial.println(sensors.getResolution(ithDeviceAddress), DEC);
}
else Serial.println(" - ERROR - Can't assign logical sensor!");
}
else {
Serial.print("Found ghost device at ");
Serial.print(i, DEC);
Serial.print(" but could not detect address - check power and cabling.");
}
}
Serial.println();
Serial.println("Sensor configuration completed.");
} // configureSensors
short getIndex(DeviceAddress _deviceAddress)
// Return index of sensor whose address matches device address.
// Sensor and device addresses need to be compared byte by byte.
// Return -1 if no match is found.
{
bool same;
for (int j=0;j<nSensors;j++) {
same = true;
for (int i=0;i<8;i++) {
if(_deviceAddress[i] != sensor[j].add[i]) {
same = false;
break;
}
}
if (same) return j;
}
// Failed to find a matching sensor
return -1;
} // getIndex
void printTemperature(DeviceAddress _deviceAddress)
// Print temperature data for specified device
{
float tempC = sensors.getTempC(_deviceAddress);
Serial.println(tempC, 2);
} //printTemperature
void printAddress(DeviceAddress _deviceAddress)
// Print specified address
{
for (uint8_t i = 0; i < 8; i++)
{
if (_deviceAddress[i] < 16) Serial.print("0");
Serial.print(_deviceAddress[i], HEX);
}
} //printAddress
void postReadings(short _sensorIndex)
// Posts data for specified sensor (if it's online)
{
if (sensor[_sensorIndex].sta == online) {
sprintf(cstat,"%s",sensor[_sensorIndex].nam);
webserver.print(cstat);
webserver.print(" : ");
webserver.print(sensor[_sensorIndex].tav,1);
webserver.printCRLF();
}
} // postReadings
void postAll()
//
{
for (int j=0;j<nSensors;j++) postReadings(j);
} //postAll
void requestReadSensors()
// Initiate read request for all sensors.
{
// sensors.requestTemperatures() issues a global temperature
// request to all sensors on the bus
sensors.requestTemperatures();
nReadings++;
if (nReadings >= maxReadings) nReadings = 0;
} //requestReadSensors
void updateReadings()
// Loop through each device, updating accumulators of corresponding sensors.
// Calculate average temperatures when nReadings == 0.
{
for(int i=0;i<nDevices;i++)
{
// Search the wire for address of ith device
if(sensors.getAddress(ithDeviceAddress, i))
{
// Update accumulator of corresponding sensor
short ithSensor = getIndex(ithDeviceAddress);
if (ithSensor >= 0) {
sensor[ithSensor].acc += sensors.getTempC(ithDeviceAddress);
// Calculate average temperature
if (nReadings == 0) {
sensor[ithSensor].tav = sensor[ithSensor].acc / maxReadings;
// Reset the accumulator
sensor[ithSensor].acc = 0.0;
}
}
}
}
} // updateReadings
void tick()
// Perform scheduled tasks on 200 ms ticks over 4000 ms cycle (20 ticks)
{
if (millis() - t0 >= 200) { // On 200 ms boundary
t0 = millis();
++nticks; // Increment tick count
if (nticks > 19) nticks = 0;
// Every 1000 ms
if (nticks % 5 == 0) {
// - Increment seconds counter, manage hours & days counter
++sec;
if ((sec % 3600) == 0) ++hourNo;
if (hourNo == 24) {
// Reset uptime counters
hourNo = 0;
sec = 0;
dayNo++;
}
}
// On 2 second tick
if (nticks == 10) {
requestReadSensors();
}
// On 4 second tick
if (nticks == 0) {
updateReadings();
}
}
} // tick
// ************************** Let the games begin *******************************
void setup(void)
{
// Start serial port
Serial.begin(19200);
Serial.println(" ");
Serial.println("*");
Serial.println("*");
Serial.print(INO_NAME);
Serial.print(" ");
Serial.println(INO_VERSION);
Serial.println("*");
// Start up the DTL
sensors.begin();
// Configure sensors
configureSensors();
Serial.end();
#if ARDUINO_UNIT_NO == 4
// MAC number and IP parameters for arduino4
// arduino4 is defined in /etc/hosts as 10.0.1.204
static uint8_t mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0x02, 0x04 };
static uint8_t ip[] = {
10, 0, 1, 204 };
#else
// MAC number and IP parameters for arduino5
// arduino5 is defined in /etc/hosts as 10.0.1.215
static uint8_t mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0x02, 0x15 };
static uint8_t ip[] = {
10, 0, 1, 215 };
#endif
// Initialize the Ethernet adapter
Ethernet.begin(mac, ip);
// Setup the default command that will run when the web client
// (curl) accesses the root page on the webserver
webserver.setDefaultCommand(&mtdsCmd);
// Start the webserver
webserver.begin();
// Grab the current time
t0 = millis();
} // setup
void loop(void)
{
char buff[64];
int len = 64;
// process incoming connections one at a time, forever
webserver.processConnection(buff, &len);
// Perform scheduled tasks on 200 ms ticks
tick();
} // loop
#!/usr/bin/env python
import urllib2
import sys
## wait until is finished
theIPnumber = '192.168.1.71'
Brightness= 1
Contrast= 1
Saturation= 1
Antiflicker= 1
MirrorOnOff= 0
map = ["1", "14", "26", "39", "51", "64", "77", "90", "103", "115", "128"]
if Brightness >= 5: Brightness = 5
if Brightness <= -5: Brightness = -5
setBrightness = map[(Brightness +5)]
if Contrast >= 5: Contrast = 5
if Contrast <= -5: Contrast = -5
setContrast = map[(Contrast +5)]
if Saturation >= 5: Saturation = 5
if Saturation <= -5: Saturation = -5
setSaturation = map[(Saturation +5)]
if Antiflicker >= 1: setAntiflicker = '1'
if Antiflicker <= 0: setAntiflicker = '0'
if MirrorOnOff >= 1: setMirrorOnOff = '1'
if MirrorOnOff <= 0: setMirrorOnOff = '0'
print setBrightness
cmd = "&ReplySuccessPage=image.htm"
cmd = cmd + "&ReplyErrorPage=errrimg.htm"
cmd = cmd +"&BrightnessControl="+ setBrightness
cmd = cmd +"&ContrastControl="+setContrast
cmd = cmd +"&SaturationControl="+setSaturation
cmd = cmd +"&AntiFlickerEnable="+setAntiflicker
cmd = cmd +"&Mirror="+setMirrorOnOff
cmd = cmd +"&ConfigSystemStream=Save"
print cmd
theURL = 'http://'+theIPnumber+'/setSystemStream'
theUserid="xxxx"
thePassword="yyyy"
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, theURL, theUserid, thePassword)
urllib2.install_opener(urllib2.build_opener(urllib2.HTTPBasicAuthHandler(passman)))
response = urllib2.urlopen(theURL,cmd)
Users browsing this forum: No registered users and 24 guests