How to set timeout when fetching content from web site with file_get_contents?
[quote]<?php
$context = stream_context_create(array(‘http’ => array(‘timeout’ > 1)));
echo file_get_contents(\"http://example.com/\", 0, $context);
?>[/quote]
It’s a good idea to use it with timeout, because otherwise default timeout from php.ini will be used.
Category Archives: Programming
PHP: file_get_contents timeout
RFID Reader
Code
Latest source code is available at http://www.dejanlevec.com/code/Microcontrollers/RFID-Reader/14-Jun-2009/.
Hex file is available only for ATmega8 at 16MHz. Host executable is available only for Intel Macs with latest software update.
Currently you need to request ID from a device.
Example: ./set-led status
Receiving ID when tag is scanned is still in progress. (I have some problems with USB interrupt-in)
Circuit
Components for USB are connected as usual. (D+ on PB2, D- on PB4). Green LED is connected to PC5 (28), yellow LED to PC3 (26). TX from RFID module is connected to RX on AVR (PB0 on ATMega8/168).
Parts
RFID module (seeedstudio – $12.50)
RFID tags (seeedstudio – $2.50)
ATmega8 microcontroller (or similar)
16Mhz quartz (or 12Mhz)
2x 3.6V or 3.3V zener diode
1x green LED
1x yellow LED
2x 68 R (or other 12 – 100 ohm resistors)
1k5 resistor
10 uF capacitor
2x 330 ohm
28 pin socket
AC Switching By Computer
I’m building a device for switching AC devices by computer program through USB. It could be used for light show, home automation system, etc.
I’ll be using 8 triacs with 8 opto-triacs (to protect microcontroller and computer from direct contact with AC line).
I haven’t build it yet because I don’t have every part needed at home. Finished circuit and working code should be published in a few days.
Short: When electric current is present on gate triac is triggered and the device conduct AC current between terminal 1 and terminal 2.
Long: http://en.wikipedia.org/wiki/TRIAC
I chose triac because it’s silent and faster than relay. Opto-triac is used to trigger triac without any risk of destroying any other elements on DC side.
a) Circuit for triac and opto-triac:

Pin 1 on MOC2061 connects through 330ohm resistor to microcontroller pin and pin 2 connects to ground.
b) Whole circuit it’s not yet available … will be soon.
- 8x MOC3061 (opto-triac)
- 8x BT139 (triac, up to 16A, 600V)
- 1x ATmega8
- 1x 28-pin socket
- 1x 12 or 16 MHz quartz
- 16x 360 ohm resistor (for triggering triac)
- 8x 39 ohm resistor
- 8x 0.01 uF 400V!! capacitor
- 8x 330 ohm resistor (for controlling opto-triac)
- 1x 10k ohm resistor (pull-up for reset pin on microcontroller)
- 2x 3.3V or 3.6V zener diode (for USB connection)
- 2x 68 ohm resistor – 1x 1,5k ohm resistor (pull-up for USB D- line)
- 1x USB type B jack (not necessary)
- 1x 10uF capacitor
- 2x 10pF – 20pF capacitor
It’s not finished because I firstly need all components. For USB communication V-USB firmware-only implementation will be used.


Recent Comments